I think guys have given all the function needed to open a text file through C. But i want to remind you that you want be able read the Containts of a Excel or word File using C.
2006-09-04 04:06:38
·
answer #1
·
answered by Piyush 2
·
0⤊
0⤋
Wel I feel all the coding is here, the correct C approach is by mentioning the stdio.h header
FILE *handle; /* [hope u know what that means; it is a file handle pointer, pointuing to the segment:offset value of the file styruicture prepared inC]*/
/* then use: fscanf(pointer,format,variable) to read and fprintf(pointer, format, variabkle) to print to a file. You can also use fgetc, fgets, fputc, fputs for the same, Use fseek to seek, and ftell to return the file position handle, which is actually long value. Use fwrite to overwrite values indatabases*/
For C++ it uses fstream.h and the coding is
fstream *handler; // for both input and output file operations
ifstream *handler1; // for only input
ofsteram *handler2; // for only output
/* REFER TO C++ documentation for help on this, Iam not too much inclined on C++ programming, sorry! But i know it is way easier in C++, by overloading objects of fstream class by opetators: >> and << for input and output operations respectively. CALL me crazy but I prefer C style*/
NOTE: Both styles compile under the standard C compiler
The Excel, Word,Bmp files are just files of spoecial formats, you know the file format and wolla!, you can access and read, modify a Excel, Word, Bmp, etc, files from ur program that Microsoft Windows can easily recogise!
2006-09-04 19:55:11
·
answer #2
·
answered by Rahul Ghose 4
·
0⤊
0⤋
I don't really know what you want but the code to read a file is simple.
ex . your file can be somthing like this :
data1 value1
data2 value2
data3 value4
let's say that data1,data2,data3 are integers and value1,2,3 are strings (without space between words)
you can read the data like this :
#include
void main(){
int data;
char value[100];
FILE *f=fopen("abc.txt","r");
while(!feof(f)){
fscanf(f,"%d",&data);
fscanf(f,"%s",&value);
//now you can process value and data in your interest nd that's it
// for exmple printf("%d %s",data,vlue);
}
}
2006-09-04 02:11:06
·
answer #3
·
answered by mirku2die4 1
·
1⤊
0⤋
C has lot of functions for file handling.
1. Open a file by using fopen( ).
ex: FILE *fp=fopen("filename", "r");
2. Char by char reading:
char ch;
while((ch=fgetc(fp)) != null) printf("%c", ch);
3. Reading line by line:
char str[81];
while(fgets(fp,str,81)!= null) printf("%s", str);
after you are done, close the file.
4. fclose(fp);
HTH.
2006-09-04 02:05:01
·
answer #4
·
answered by Indian_Male 4
·
0⤊
0⤋
elementary, open a streamreader and streamwriter on the comparable time. you will could desire to regulate the area of the report cursor as you pass alongside. this might create the flow: FileStream fileStream = new FileStream(@"c:report.txt", FileMode.Create); // you're able to desire a distinctive mode and then create reader and author with that flow.
2016-10-01 07:18:06
·
answer #5
·
answered by ? 4
·
0⤊
0⤋
char buffer[4096];
FILE *f = fopen( full_path_name, "rt" );
while( fgets( buffer, 4096, f ))
{
/* do something with the data you have read. */
}
fclose( f );
2006-09-04 02:08:32
·
answer #6
·
answered by alakit013 5
·
0⤊
0⤋