954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

adding columns in .csv file using C

hey guys!
how do i calculate the sum of a column in .csv file format using C?
e.g my fie looks like this
1, 2, 3, 4
2, 3, 4, 5
3, 4, 5, 6

(the ',' shows new cell)

how do i calculate sum of each column (desired answer is like 6,9,15)

can i do it using fscanf()? if yes, how?

thanks!

Ammara Sajid
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

Read each line
Convert the first value to integer.
Skip over characters until you find the ','
Convert the next value to integer.
Skip over characters until you find the ','
continue until done.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

ummmmm...how? how do i use fscanf() for this? how do i modify the second argument of fscanf(f,"%d,[^,],%[^n]",&n) so that it reads every value in a row till \n in different variables?

Ammara Sajid
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
ummmmm...how? how do i use fscanf() for this?


I never suggested fscanf() . Use a command that can read an entire line.how do i modify the second argument of fscanf(f,"%d,[^,],%[^n]",&n) so that it reads every value in a row till \n in different variables?
Don't bother. Use a command that can read the file easier and process the line yourself.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: