Last active
February 2, 2020 16:10
-
-
Save winhtut/d98954bc13405ce79cf8553304cc4a5d to your computer and use it in GitHub Desktop.
Reading Data From File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main(){ | |
FILE *fptr; | |
if((fptr=fopen("clients.txt","w"))==NULL){ | |
puts("File could not be opened"); | |
} | |
else{ | |
puts("Enter the account , age , name , balance"); | |
puts("Enter EOF to end input."); | |
printf(">:"); | |
unsigned int account; | |
int age; | |
char name[30]; | |
double balance; | |
scanf("%d%d%20s%lf",&account , &age , name , &balance); | |
while(!feof(stdin)){ | |
fprintf(fptr,"%d %d %s %.2f \n",account ,age, name , balance); | |
printf(">:"); | |
scanf("%d%d%20s%lf",&account ,&age , name , &balance); | |
} | |
} | |
fclose(fptr); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
FILE * fptr; | |
char c; | |
printf("__Reading all data From File ___\n"); | |
fptr = fopen("001testw.txt", "r"); | |
while ((c = getc(fptr)) != EOF) { | |
printf("%c", c); | |
} | |
fclose(fptr); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
FILE * fptr; | |
char data_buffer[40]; | |
fptr = fopen("1hello.txt", "r"); | |
printf("__Reading a line From File__\n"); | |
fgets(data_buffer,50,fptr); | |
printf("%s\n",data_buffer); | |
fclose(fptr); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
FILE * fptr; | |
char data1[20],data2[20],data3[20],data4[20]; | |
fptr = fopen("1hello.txt", "r"); | |
printf("__Reading datas parse by parse From File__\n"); | |
fscanf(fptr,"%s %s %s %s ",data1,data2,data3,data4); | |
printf("Reading a string :%s \n",data1); | |
printf("Reading a string :%s \n",data2); | |
printf("Reading a string :%s \n",data3); | |
printf("Reading a string :%s \n",data4); | |
fclose(fptr); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
FILE *fptr; | |
fptr= fopen("1hello.txt","r+"); | |
char data1[20],data4[20]; | |
int code=0; | |
float balance=0.0; | |
printf("________Reading data parse by parse from specific file______\n"); | |
fscanf(fptr , "%d %s %f %s",&code,data1,&balance,data4); | |
printf("Reading data from file 1 st %d\n",code); | |
printf("Reading data from file 2 st %s\n",data1); | |
printf("Reading data from file 3 st %.2f\n",balance); | |
printf("Reading data from file 4 st %s\n",data4); | |
fclose(fptr); | |
return 0; | |
} |
Thanks you too
…On Thu, Dec 12, 2019, 9:03 AM WinLae-46 ***@***.***> wrote:
Thanks you sir
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/d98954bc13405ce79cf8553304cc4a5d?email_source=notifications&email_token=AHC3SY7JTSYTZEANDXB4AMLQYGPJHA5CNFSM4JZO7HKKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF5YGC#gistcomment-3108961>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHC3SY7P6MIQG4AKSKZOB6DQYGPJHANCNFSM4JZO7HKA>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good teacher