#### Archived

This topic is now archived and is closed to further replies.

# file i/o

This topic is 5893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If have a textfile which looks like this: ; lengt 1000 ; start 0 ; jump 100 700.000 3 100.000 4 Now i open the file with fopen and then i want to pass the lines with a ; and go to the numbers below and read them one by one and store them in a buffer. How can this be done. How can a pass all the lines with a ; and read those numbers until i find an end of file? Thanx in advance

##### Share on other sites
Read the file a line at a time, and any line that begins with a '';'' skip. Kind of like this:
  /* Assumes less than 512 on each line for simplicity*/char Buffer[512];FILE *File = fopen(...);/* ... */for( ; ; ) { if(fgets(Buffer,512,File) == NULL) break; switch(Buffer[0]) { case '';'': break; default: /* Get Number from Buffer with atof or sscanf */ break; }}fclose(File);

[Resist Windows XP''s Invasive Production Activation Technology!]

##### Share on other sites
But how about the points in the file. Does the computer see that as thousands or as a decimal divider?? And i want the numbers to be written in an array of characters and then send them over. but how do i recognize the different numbers in an array of characters because they do not fit in one memory location of the array?

ANYONE??

##### Share on other sites
Depending on how you open the file it will either see the decimals as a single byte value or as a character ''.'' Although technically they''re both the same thing, it might be more meaningful in a given situation to think of it a certain way. You might be able to pull something off with fscanf() to get it to read the 700.000 as a fractional number. No matter what, you''ll have to tell your program how to deal with it.

ASCII mode files are cooky to work with IMHO.

• ### Forum Statistics

• Total Topics
628726
• Total Posts
2984411

• 25
• 11
• 10
• 16
• 14