0

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!

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by WaltP
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.

0

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?

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.