C programming help!!!

Joined
5 Aug 2006
Posts
11,419
Location
Derbyshire
I am writing a C programme (not # or ++) that will use functions in order to read a .dat or .txt file that has x and y values, do some maths calcs on it, and then write the result to another file.

Dynamic memory has to be used as any number of lines of data could be in the file (so a linked list).

There needs to be a function to ask user for filenames, a function to read the file, a function to do the calcs and a function to write to a file.

Anyone got an examples of questions similar to this, or know of any websites?

Have tried many different google searches - Which 95% seem to be explaining a linked list or explaining functions, rather than actually show any examples.
 
Surely whatever course you're doing requires you to learn programming, copying from examples isn't learning to program.

Think about what you need to do, eg accepting filenames, assuming command line only based then you simply need to write out to the console and then accept input back, maybe do some error checking and that's it, trivial.

Reading the file, I believe one of your questions was on reading a file in, so you know how to do this, if not, fgets or something similar will do the job.

calcs, well, that's not hard is it...

Writing to a file, reverse of reading it I presume, fprintf sounds like a possible candidate.
 
I recommmend the book C by dissection, it has loads of examples and explains how plenty of the C function work.

scanf is the function required to read from the command line.

As mentioned above, you must be careful not to just copy examples as some courses and extremely complex plagiarism checkers.

Gaunt
 
Back
Top Bottom