Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int n, i, number;
- char subject[30];
- FILE *fp;
- printf("How many subjects? ");
- scanf("%d", &n);
- getchar();
- if((fp = fopen("input.txt", "w")) == NULL)
- {
- printf("Error opening file.\n");
- exit(1);
- }
- for(i = 0; i < n; i++)
- {
- printf("Enter the name of subject %d: ", i+1);
- gets(subject);
- printf("Enter the marks of subject %d: ", i+1);
- scanf("%d", &number);
- getchar();
- fprintf(fp, "%s %d\n", subject, number);
- }
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement