Skip to content

Instantly share code, notes, and snippets.

@mr-fool
Last active August 29, 2015 14:07
Show Gist options
  • Save mr-fool/78662782400d8b202b36 to your computer and use it in GitHub Desktop.
Save mr-fool/78662782400d8b202b36 to your computer and use it in GitHub Desktop.
file i/o C practice
#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;
}
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