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!

Recommended Answers

All 3 Replies

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.

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.