Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Text File

Status
Not open for further replies.

PaolaS

Programmer
Aug 23, 2001
8
ES
I have in my text file:

Sandra Bullock
Edmundo Wilson
Daniel Perez
Peter Julius
Anthony Hopkins
Paola Sandoval
Giovanna White

But, I want learn the second row, from the position 3 to 7
the word "mundo".

If anybody knows the code for it, I will be thanksfully.

Paola S


 
Hi Paolas
Your problem can be solved easily if you are writing into file by a fixed length array. Then what you have to do is that which ever line you have to read first set your file pointer to that position.
Like
chat arr[50];
FILE *fp = fopen(filename,"r");
fseek(fp,(sizeof(arr) * no of record to be read)+2,SEEK_SET);
fread(arr,sizeof(char),4,fp);
arr here will contain from third element to 7th element.
 
If its not fixed length, you may ...

1) Search for the newlines...
or,
2) Read the file line by line (using getline) till u get to the line u require, and then use strtok( )...

Hope this helps.:) Ankan.

Please do correct me if I am wrong. s-)
 
Make that strncpy( ), not strtok( ). Sorry for the mistake. :) Ankan.

Please do correct me if I am wrong. s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top