In here I was taught of how i make programs that can process files, or basically manipulate files haha.
Here's how I open a file,
1. first we need to input a variable to represent the file.
Syntax:
FILE *fp;
2. And we open the file. for example, we want to write on a file called "output.txt" in data D.
Syntax:
fp = fopen("D:\\output.txt","w"); //w here means write
3. We use "fprintf" to print inside the txt file.
Syntax:
fprintf(fp,"Hello World!");
And the result is, there will be a text "Hello World!" inside output.txt in Data D.
Here's how I read it,
1. Input the variable like this.
Syntax:
fp = fopen("D:\\output.txt","r"); //r here means read
2. you can scan the data in the output.txt file by using "fscanf". Here's how it's done.
Syntax:
fscanf(fp,"%s",a);
//if we print a, it will be "Hello".
With all these lectures, it is said that file can be processed and manipulated through programs.
No comments:
Post a Comment