ফাইল থেকে তথ্য ব্যবহার করবো কিভাবে?
* কোনো file এর information :
Rahim = 20;
Karim =25;
Jabbar =13;
Rakib =27;
একটি programme তৈরি করবো
#include
int main()
{ char name[10];
printf("Enter A Student's Name : ") ;
scanf(" %s",&name);
............................................................
............................................................
return 0;
}
এখন scan করা উক্ত নাম এর মান file থেকে print করবো কিভাবে ?
2532 views
1 Answers
- // file থেকে read
-
-
#include
-
#include
- int main()
- {
- char ch, file_name[25];
- FILE *fp;
- printf("Enter name of a file you wish to see\n");
- gets(file_name);
- fp = fopen(file_name, "r"); // read mode
- if (fp == NULL)
- {
- perror("Error while opening the file.\n");
- exit(EXIT_FAILURE);
- }
- printf("The contents of %s file are:\n",file_name);
- while((ch = fgetc(fp)) != EOF)
- printf("%c", ch);
- fclose(fp);
- return 0;
- }
2532 views
Answered
Related Questions
Next steps
- Find a doctor for in-person or online consultation
- Browse medical tests patients often ask about
- Check medicine information (uses, dosage, brands in Bangladesh)
- More health Q&A on Bissoy