You are here:

C/C-- parsing data from file

Advertisement


Question
Dear Narendra,

I am started in C program. I have to do a program which read and write data from a file and should be saved in a array for manipulation. So can u gimme an example program which read & write in file, also storing the value of data in array. please reply me..

thanx in advance

regards,
suresh

Answer
Instead of trying to get readymade programs (spoon feeding), try to study the book and trying out yourself.
First of all, find out what are the API's that are used for this.
You will need an API to open the file - fopen().
To read the file - fread() or fscanf() or fgets() or fgetc().
To write to file - fwrite(0 or fprintf() or fputs() or fputc().
To find the position in the file - ftell().
To go to any place in the file - fseek().
To close the file - fclose().

So, you have to learn all these API's and then start writing the sample code. Start studying the man pages for these and you will soon become an expert in these.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.