Hello mga kuys! Please pa help HAHAHHAHA been debugging this since morning tas di ko alam pano eh.
Pano ba mag lagay ng file extension na .txt sa C File handling instead of typing it manually as a user?
Bale ang magiging name ng file is depende sa name ng student na ininput as a user
Example: Juan
Tapos yung name naman ng file is magiging Juan.txt dapat.
Here's my code po.
Pano ba mag lagay ng file extension na .txt sa C File handling instead of typing it manually as a user?
Bale ang magiging name ng file is depende sa name ng student na ininput as a user
Example: Juan
Tapos yung name naman ng file is magiging Juan.txt dapat.
Here's my code po.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE * fptr;
int i, n;
int id, math, sci, eng, sum = 0, ave = 0;
char name[255];
printf("Input how many students: ");
scanf("%d", & n);
for (i = 0; i < n; i++) {
printf("\nEnter student name: ");
fgets(name, sizeof name, stdin);
scanf("%s", name);
fptr = fopen(name, "w");
printf("Student ID Number:");
scanf("%d", &id);
printf("Math Grade:");
scanf("%d", &math);
printf("Science Grade:");
scanf("%d", &sci);
printf("English Grade:");
scanf("%d", &eng);
printf("\nData written succesfully!");
sum = math + sci + eng;
ave = sum / 3;
fprintf(fptr, "Student Name: %s", name);
fprintf(fptr, "\nStudent ID number: %d", id);
fprintf(fptr, "\nMath Grade: %d", math);
fprintf(fptr, "\nScience Grade: %d", sci);
fprintf(fptr, "\nEnglish Grade: %d", eng);
fprintf(fptr, "\nTotal grade: %d", sum);
fprintf(fptr, "\n\nGrade average: %d", ave);
}
return 0;
}
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.