File Processing
if you'd like to open a file and read from that file or you want to write a file based on what you've inputted on your program, this is the way.
i'll explain how to read and write file.
read file, it is easier to make a function just to read file, so i'll just make a function.
int readFile() {
//there are 3 process here, first is open the file, the reading process, and last but not least close the file.
FILE * fp = fopen("/*this id the file name, the one you'd like to read*/", "r"); // r means read
while(!feof(fp)) { //feof means end of file, so as ling as there are something to read, they'll scan it
fscanf(fp, "/*this is the file format, e.g. %s#%d", /*this is where you want to put the file to*/
}
fclose(fp);
}
for the write file you'll just do the same thing but jut change the "r" to "w" and fscanf to fprintf syntax.
see, not that complicated.
good luck.
if you'd like to open a file and read from that file or you want to write a file based on what you've inputted on your program, this is the way.
i'll explain how to read and write file.
read file, it is easier to make a function just to read file, so i'll just make a function.
int readFile() {
//there are 3 process here, first is open the file, the reading process, and last but not least close the file.
FILE * fp = fopen("/*this id the file name, the one you'd like to read*/", "r"); // r means read
while(!feof(fp)) { //feof means end of file, so as ling as there are something to read, they'll scan it
fscanf(fp, "/*this is the file format, e.g. %s#%d", /*this is where you want to put the file to*/
}
fclose(fp);
}
for the write file you'll just do the same thing but jut change the "r" to "w" and fscanf to fprintf syntax.
see, not that complicated.
good luck.
Comments
Post a Comment