0

hey there,
i want to write a c program to read array from a text file .....which looks something like this
ex.txt
123
245
465
12
37
84
984

i want to write a program to read these values and subtract each value from the next one(like 245-123,465-245,....and so on till end of file) and store result into another txt file.
i would be glad if somebody could suggest me how to do this.
Thank you very much.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Salem
0

lets say you have two integers, n1 and n2

open file for input
read first integer into n1
start of loop to read until end-of-file
   read integer into n2
   subtract n2 - n1 and save result in a second file
   move value of n2 into n1
end of loop
0

Can you show me an example.
that would be very helpful.

0

Why don't you give it a go, see how far you get, then post what you can achieve yourself.

Then we'll tell you where you're going wrong, and suggest how you should proceed towards your goal.

It'll teach you a lot more than simply looking at someone else's code.

You can't become a great cook simply by being a food taster.

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.