ফাইলের শেষ (EOF) ইনপুটের শেষ নির্দেশ করে।
আমরা টেক্সট প্রবেশ করার পরে, আমরা যদি ctrl+Z চাপি, পাঠ্যটি বন্ধ হয়ে যায় অর্থাৎ এটি নির্দেশ করে যে ফাইলটি পড়ার জন্য কিছুই নেই।
অ্যালগরিদম
EOF এর জন্য নিচে দেওয়া অ্যালগরিদম পড়ুন।
Step 1: Open file in write mode. Step 2: Until character reaches end of the file, write each character in filepointer. Step 3: Close file. Step 4: Again open file in read mode. Step 5: Reading the character from file until fp equals to EOF. Step 5: Print character on console. Step 6: Close file.
উদাহরণ
ফাইলের সমাপ্তি (EOF) -
এর জন্য C প্রোগ্রামটি নিচে দেওয়া হল#include <stdio.h>
int main(){
char ch;
FILE *fp;
fp=fopen("std1.txt","w"); //open the file in write mode
printf("enter the text then press cntrl Z:\n");
while((ch = getchar())!=EOF) //reading char by char until it equals to EOF{
i.e. when u press ctrlZ the while loop terminates
putc(ch,fp);
}
fclose(fp);
fp=fopen("std1.txt","r");
printf("text on the file:\n");
while ((ch=getc(fp))!=EOF) //reading the character from file until fp equals to EOF{
putchar(ch);
}
fclose(fp);
return 0;
} আউটপুট
যখন উপরের প্রোগ্রামটি কার্যকর করা হয়, তখন এটি নিম্নলিখিত ফলাফল তৈরি করে -
enter the text then press cntrl Z: This is the EOF demonstration example if your text typing is over press cntrlZ ^Z text on the file: This is the EOF demonstration example if your text typing is over press cntrlZ