Re: [Dev-C++] newbie string parsing question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Matt V. <m-v...@on...> - 2004-08-17 23:15:48
|
Look up the fscanf() function.
pseudo-code:
#include <stdio.h>
char* first_name;
char* last_name;
int age;
FILE* in_file;
infile = fopen("data.txt","r");
while ( !eof(infile) ) {
fscanf( infile, "%s\t%s\t%d\r", first_name, last_name, &age);
// do something with the first_name, last_name, and age variables here.
}
close(infile);
I think that's right -- might want to double check all of the pointers
and stuff (the * and & operators). I'm just typing this off the top of
my head so double check the syntax.
-Matt
wor...@so... wrote:
> Hi all,
>
> Thank you in advance for any help that you can offer.
>
> I have a text file that has records like this:
>
> Firstname Lastname age //seperated by the \t character.
>
> I want to run a while loop and parse the record to populate a struct array.
> I have looked into the getline(string, max, delimiter) function but it needs char[]'s.
> Since I don't know the length of the string that I need can someone recommend
> an existing different class function or something?
>
> Best regards,
>
> Dane
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
> 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
> Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
> http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|