a little help please

Posts 1–9 of 9 · Page 1 of 1
a little help please
EDIT : NVM. I just found that I need to change

char *motTest = motRecherche;

to
char *motTest;


REQUEST CLOSE /Sorry.


Code:
int main()
{
    int longueur = strlen("Bonjour");
    char motRecherche[] = "Bonjour";
    char *motTest = motRecherche;
    strcpy(motTest, motRecherche);
    char lettre[1];
    strset(motTest,'*');
    int c = 0;
    int i = 0;
    do
    {
        cout << "Entrez une lettre pour trouver le mot...   :   " << motTest << endl;
        cin >> lettre[0];

        for(i = 0 ; i<longueur ; i++)
        {
            if(lettre[0] == motRecherche[i])
            {
                motTest[i] = motRecherche[i];
                cout << endl << endl;
                cout << "done";
            }
        }
    }while(c == 0);



    cout << "Vous avez trouver la reponse!";

    return 0;
}
So if I enter 'o', it still doesn't enter in the :

Code:
if(lettre[0] == motRecherche[i])
            {
                motTest[i] = motRecherche[i];
                cout << endl << endl;
                cout << "done";
            }
Any help please?
Possibly try this if dont want change the initialization of motTest

char * motRecherche[1] = {"Bonjour"};
char * motTest = motRecherche[0];
I love it when people solve their own problem! congratz. =)
Another help please? xD

Code:
#include <iostream>
#include <cstring>


using namespace std;

int main()
{
    int longueur = strlen("Bonjour");
    char motRecherche[] = "Bonjour";
    char *motTest;
    strcpy(motTest, motRecherche);
    char lettre[1];
    strset(motTest,'*');

    while(strcmp(motTest, motRecherche) != 0)
    {
        cout << "Entrez une lettre pour trouver le mot...   :   " << motTest << endl;
        cin >> lettre[0];

        for(int i = 0 ; i<longueur ; i++)
        {
            if(lettre[0] == motRecherche[i])
            {
                motTest[i] = motRecherche[i];
                cout << endl << endl;
            }
        }
    }



    cout << "Vous avez trouver la reponse!";

    cin.get();

    return 0;
}
So I can build and run it, but when i run it, nothing happen, it just crashes... any help?
motTest is a nullpointer.
change it to char motTest[];
Quote Originally Posted by Hell_Demon View Post
motTest is a nullpointer.
change it to char motTest[];
||=== Find a word, Debug ==
C:\Users\Gabriel\Desktop\Programmation\Find a word\main.cpp||In function 'int main()':|
C:\Users\Gabriel\Desktop\Programmation\Find a word\main.cpp|11|error: storage size of 'motTest' isn't known|
||=== Build finished: 1 errors, 0 warnings ==

storage size of 'motTest' isn't known

isn't it undefined now?


EDIT :

Code:
#include <iostream>
#include <cstring>


using namespace std;

int main()
{
    int longueur = strlen("Bonjour");
    char motRecherche[] = "Bonjour";
    char *motTest;
    strcpy(motTest, motRecherche);
    char lettre[1];
    strset(motTest,'*');
    int c = 0;

    while(c == 0)
    {
        cout << "Entrez une lettre pour trouver le mot...   :   " << motTest << endl;
        cin >> lettre[0];

        for(int i = 0 ; i<longueur ; i++)
        {
            if(lettre[0] == motRecherche[i])
            {
                motTest[i] = motRecherche[i];
                cout << endl << endl;
            }
        }
    }



    cout << "Vous avez trouver la reponse!";

    cin.get();

    return 0;
}
That code work... I think the problem is

Code:
while(strcmp(motTest, motRecherche) != 0)
char motTest[8]; then, since Bonjour has 7 characters :3
Thanks to everyone.
I got something that work.

Code:
#include <iostream>
#include <cstring>


using namespace std;

int main()
{
    int longueur = strlen("Bonjour");
    char motRecherche[] = "Bonjour";
    char *motTest;
    strcpy(motTest, motRecherche);
    char lettre[1];
    strset(motTest,'*');
    int c = 0;

    while(c == 0)
    {
        cout << "Entrez une lettre pour trouver le mot...   :   " << motTest << endl;
        cin >> lettre[0];

        for(int i = 0 ; i<longueur ; i++)
        {
            if(lettre[0] == motRecherche[i])
            {
                motTest[i] = motRecherche[i];
                cout << endl << endl;
            }
        }
        if(strcmp(motRecherche, motTest) == 0)
        {
            c = 1;
        }
    }



    cout << "Vous avez trouver la reponse!";

    cin.get();

    return 0;
}
request Close
~ Closed on request ~
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Talk with us