Last active
August 29, 2015 14:07
-
-
Save mr-fool/78662782400d8b202b36 to your computer and use it in GitHub Desktop.
file i/o C practice
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> | |
#include <stdlib.h> | |
int main(void) { | |
int studentID; | |
char name[100]; | |
float balance; | |
//file pointer | |
FILE *fee; | |
if ( (fee = fopen("fee.txt","w") ) == NULL) { | |
printf("File could not be opended\n"); | |
exit(0); | |
} | |
else { | |
printf("Please enter the studentID, name, and fee owed\n"); | |
printf("Enter EOF to end input\n"); | |
scanf("%d%s%f",&studentID, name,&balance); | |
fprintf(fee,"%s\t%s\t%s\n","Student ID","Student Name","Fee Owed"); | |
while (!feof(stdin) ) { | |
fprintf(fee,"%d\t\t%s\t%f\n", studentID, name, balance); | |
scanf("%d%s%f",&studentID, name,&balance); | |
} | |
fclose(fee); | |
} | |
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
allFiles: fee.c | |
gcc -Wall fee.c -o fee.out -lm | |
clean: | |
rm *.o fee.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment