Go Down

Topic: auto reset during the loop() (Read 2141 times) previous topic - next topic

gigiZ

I am giving the code because there are errors:

Code: [Select]

int rechercheUtilisateur(char numUtilisateur[TAILLE_NUM_UTI]){
    int i, ligne = 1;
    //declaration des tableaux locaux   
    char numString[TAILLE_NUM_UTI];

    //place le pointeur au debut du fichier
    myFile.seek(0);
    //recupére le numéro d'identifiant de la ligne
    for(i=0; i<TAILLE_NUM_UTI-1; i++) numString[i]=myFile.read(); 
    numString[i]='\0';

   
    while(strcmp(numUtilisateur, numString)){
        if(!sautDeLigne()){
          myFile.seek(0);
          return 0;
        }
     
        ligne++;
        //met dans 'numString' le numéro d'identifiant de la ligne
        for(i=0; i<TAILLE_NUM_UTI-1; i++){
          numString[i]=myFile.read();
        }
        numString[i]='\0';
    }
    //place le pointeur au debut de la ligne
    myFile.seek(myFile.position()-TAILLE_NUM_UTI);
    return ligne;
}


TAILLE_NUM_UTI is defined in the beginning of the code:
Code: [Select]
#define TAILLE_NUM_UTI 8+1

Do you want the entire program?

pylon

Yes, please give us the whole program and also tell us what's in the file you're reading in.

michael_x

BTW:
Code: [Select]
#define TAILLE_NUM_UTI 8+1
is dangererous:

int x = TAILLE_NUM*4; // x = 12 !!!

better say
#define TAILLE_NUM_UTI (8+1) 

PaulS

Code: [Select]
    while(strcmp(numUtilisateur, numString)){
strcmp() returns 0 if the strings match, or -1 or +1 if they don't match, depending on whether string 1 comes before or after string 2. It does NOT return a boolean, so this code should not be written as though it does. Explicitly state what you are expecting.

Code: [Select]
    for(i=0; i<TAILLE_NUM_UTI-1; i++) numString[i]=myFile.read(); 
Suppose you read past the end of the file. Then what happens?

Some Serial.print()s in this code will tell you where you are going wrong. Why are there none?

gigiZ


Some Serial.print()s in this code will tell you where you are going wrong. Why are there none?

I've watched with Serial.println () but that the reset occurs at different times if I change the code.


Code: [Select]
    for(i=0; i<TAILLE_NUM_UTI-1; i++) numString[i]=myFile.read(); 
Suppose you read past the end of the file. Then what happens?

I normally can not to be at the end of the file, I read the first 8 characters of a great line.

The Clever Monkey

#20
May 14, 2012, 06:52 pm Last Edit: May 14, 2012, 06:55 pm by The Clever Monkey Reason: 1
Quote


Code: [Select]
   for(i=0; i<TAILLE_NUM_UTI-1; i++) numString[i]=myFile.read();  
Suppose you read past the end of the file. Then what happens?

I normally can not to be at the end of the file, I read the first 8 characters of a great line.

What if your file contains less than 8 bytes?

You really ought to be checking for unexpected results from read().
I yield() for co-routines.

Go Up