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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading lines with more than 256 characters

Status
Not open for further replies.

inderw

Vendor
Apr 26, 2007
1
AU
Hi. I am trying to read a file (csv) which has more that 256 characters in a line. I want to read the whole line and extract some information. I am using comma as a seperator.

At the moment, I am reading a line using fgets and placing the tokens in an array using strtok. Then I fgets the same line again and continue placing the token in the same array.

The problem I am having is that as I have no control over where the fgets will finish, I am not able to do proper extraction based on commas.

Can someone help please.
 
The problem is FGETS is getting from the file as a string, so 256chars per line is the limit.

My only thought is for you to edit your csv file to indicate the end of each line,with some sort of text indicator i.e. "<ENDLINE>". Then modify your current CSV file so each cell of data appears on its own line.

Now at least you have the option... [UGLY AS IT IS]
Of processing the file and each FGETS will step through 1 cell at a time. You will of course then need to watch for "<ENDLINE>" to know you are at the end of what was originally one line.

Beautiful it ain't.... But it is the only way I can think that will work.

[red]Are there any prettier, more sensible ideas out there folks??[/red]
 
That's pretty much the only way to handle this situation. If you only needed certain portions of the line and not every piece of data, you could consider using the fseek command to position the file pointer to skip over bits of the file. If you go to the link below and search for 256, you can find a script that shows how to use this command:


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top