CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Parsing a string from fat file

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jaime



Joined: 25 Nov 2005
Posts: 56
Location: Porto - Portugal

View user's profile Send private message Visit poster's website

Parsing a string from fat file
PostPosted: Tue Sep 08, 2009 2:52 pm     Reply with quote

Hello
I'm using the ccs FAT drive to record readings from a GPS with no problem.

Now I would like to read from a file. I would like to read from config.txt the value of the interval between readings. I create a file named config.txt in the mmc card, and I write in the file #180# then the pic must read between ## the value and convert it to long int.

Any ideas to make it easy?

Thanks

jagsilva


Last edited by jaime on Wed Sep 09, 2009 6:46 pm; edited 1 time in total
jaime



Joined: 25 Nov 2005
Posts: 56
Location: Porto - Portugal

View user's profile Send private message Visit poster's website

PostPosted: Wed Sep 09, 2009 5:23 pm     Reply with quote

OK, I have this:
I read from the file one char and put in the valor[v] and I want to finish this do...while if I get one EOF or if v>5 or if char_in is a '*'.
It isnt working because it only get out of the do_while when i receive a EOF. The printf shows
Code:
*123*testing testing


What I want to do is to read the value inside the *xxx* and convert it to a int.
Code:

char char_in;
int v=0;
char valor[20];

do{
   char_in = fatgetc(&stream); //fatgetc returns an sint
   valor[v++] = char_in;
   }while(char_in != EOF || v<5 || char_in != '*') ;

valor[v]="\0";

printf("%s", valor);


Any ideas?

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 5:51 pm     Reply with quote

I think your logic is wrong in your test. I think you want to stay in the
loop if all those things are true. You should change from the logical OR
operator to the logical AND operator (&&). However, there is still a bug
because it will drop out of the loop on the very first asterisk (*).

Also, you would have got more responses more quickly if you had put
the question in terms of parsing a stream, rather than an MMC/SD Card
FAT file system problem. There are only a very few people on here
who want to trouble-shoot such things, but a lot who will handle parsing
questions.
jaime



Joined: 25 Nov 2005
Posts: 56
Location: Porto - Portugal

View user's profile Send private message Visit poster's website

PostPosted: Wed Sep 09, 2009 7:16 pm     Reply with quote

thanks for your help.

I didn't see my error. Should be &&.

Well about the code. The idea is to have a logger and in the mmc I can create a txt file with some configurations.
I don't care about the length of file I just know that I must read the characters inside two **, convert it to a string and them to an int.
The solution that I found was the code above:
Code:

do{            //look for an *
      char_in=fatgetc(&stream);
   }while(char_in != EOF && char_in != '*');

if(char_in=='*')            //found a * so keep the value till found next *
   {
   v=0;
   do{            //record till EOF or next * and the value must be under 5 digit
      valor[v++]=fatgetc(&stream);
      }while(valor[v-1] != EOF && valor[v-1] != '*' && v<=5);   
   
   if(v>5 || valor[v-1]==EOF)            //value too big or didnt find second *
      contagem=1;
   else                //value found convert to int
      {   
      valor[v-1]='\0';
      contagem=atol(valor);
      }
   }
else            // didnt found a * so contagem=1
      contagem=1;


What do you think about that?

thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group