The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
processing a file with sed and awk manouche Shell Programming and Scripting 4 10-11-2007 04:25 PM
Have a shell script check for a file to exist before processing another file heprox Shell Programming and Scripting 3 11-14-2006 03:26 AM
File processing on perl garric Shell Programming and Scripting 2 09-01-2006 11:25 PM
processing line in file fablef00 Shell Programming and Scripting 8 01-23-2006 11:41 AM
Processing a text file TheCrunge UNIX for Dummies Questions & Answers 1 11-09-2005 11:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2007
janemary.a janemary.a is offline
Registered User
  
 

Join Date: May 2007
Posts: 12
Question Processing a CSV file

Hi

I'm reading a comma separated file record by record. After reading a record, I'm tokenizing it using strtok() function and moving the tokens into a structure.

But suppose if a record is of the following format,i.e two commas appear one after another, then the strtok function skips the blank token and moves to next token. But I want to Move a blank space into the corresponding structure member. How can i solve this pbm ? Can anyone help me with this please ?

123,0,2,,123

Thanks,
Jane A
  #2 (permalink)  
Old 05-11-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,932
I have encountered this kind of problem !

I dont think we could use strtok to have solution as u desire ( I dont know )

Quite an easy way to tackle is,
parse the record using the delimiter.

for ,

123, 1, ,, 45

parse the record till the end of the line delimiter
when delimiter ' , ' is encountered you have a token
when a delimiter ' , ' follows another delimiter ' , ' obviously the string would have nothing hence the purpose would be solved

Hope this helps !
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0