PDA

View Full Version : read file with C


Outlaws
12-14-2007, 02:37 PM
i have some project from my school.
the problem like this,

i want to make C program which can read number from file, sort them, and put them into a file again.

can you help me to solving this problem?

Gox
12-14-2007, 02:42 PM
What specifically are you having trouble with?

You'll want to figure out how to read from a file to start with. Here are a couple links that may help with that.
http://www.mrx.net/c/readfunctions.html
http://www.phanderson.com/files/file_read.html

Outlaws
12-14-2007, 03:00 PM
What specifically are you having trouble with?

You'll want to figure out how to read from a file to start with. Here are a couple links that may help with that.
http://www.mrx.net/c/readfunctions.html
http://www.phanderson.com/files/file_read.html
the problem,
i must read number from a file, change it to integer, save to array, sort them, change sorted integer to number, and put them into other file.

thanks for you links..

abduraooft
12-14-2007, 03:05 PM
What you've done so far?

Outlaws
12-14-2007, 03:22 PM
yes,
can you help me to solve this ??

Gox
12-14-2007, 03:41 PM
No one here will do your school work for you. We will however help you with specific issues that you may have and help you trouble shoot your code.

Feel free to post your code so that we can better advise you as to where your errors may be located.

Active X
12-14-2007, 04:26 PM
Hi outlaws , Maybe the below snippet helps you , But the sorting method is your code to write !


#include <fstream.h> // The header file that contains required code for workin with files
#include <string.h> // The header file containing the definition of STRING type

int main()
{
fstream file; // "iofstream" stands for "Input Output File Stream" . Other options are ifstream and ofstream

string fileStr;
fileStr << file; // Reads the entire text from file;

// ... Data manipulation code goes here

fileStr >> file; // Writes the data to file;
file.close();

return 0;
}



I'll let you know if I found how to read a line separately as soon as possible , However , other friends do not stop helpin .

Have a nice time !