Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- void verif(FILE *f, char *nume) {
- if (!f) {
- printf("Fisierul %s nu s-a deschis!", nume);
- }
- }
- typedef struct {
- int nr;
- char nume[30];
- int grupa;
- char pp[3];
- int pt[20];
- char pe[3];
- }Student;
- //"%3d %-30s %18d %10s %10s %9s"
- void BinInText(char *numeBin, char *numeTxt, Student s) {
- FILE *f, *g;
- int i;
- f = fopen(numeBin, "rb"); verif(f, numeBin);
- g = fopen(numeTxt, "w"); verif(g, numeTxt);
- fprintf(g, "Nr. Nume %30s Grupa Pct proba Pct teme %10s Pct examen\n", " ", " ");
- fread(&s, sizeof(Student), 1, f);
- while(!feof(f)) {
- fprintf(g, "%3d %6s %30d %10s", s.nr, s.nume, s.grupa, s.pp);
- for(i = 0; i < 10; i++)
- fprintf(g, " %d ", s.pt[i]);
- fprintf(g, "%s\n", s.pe);
- fread(&s, sizeof(Student), 1, f);
- }
- fclose(g);
- fclose(f);
- }
- void main() {
- FILE *f;
- Student s;
- char s1[20], s2[20];
- int i;
- printf("Fisier: "); gets(s1);
- f = fopen(s1, "wb"); verif(f, s1);
- printf("Fisier text: "); gets(s2);
- printf("Nr. mat: "); scanf("%d", &s.nr);
- while (!feof(stdin)) {
- fflush(stdin);
- printf("Nume: "); fgets(s.nume, sizeof(s.nume), stdin);
- size_t length = strlen(s.nume);
- if(s.nume[length-1] == '\n') s.nume[length-1] = '\0';
- fflush(stdin);
- printf("Grupa: "); scanf("%d", &s.grupa);
- fflush(stdin);
- printf("Pct proba: "); fgets(s.pp, sizeof(s.pp), stdin);
- length = strlen(s.pp);
- if(s.pp[length-1] == '\n') s.pp[length-1] = '\0';
- fflush(stdin);
- printf("Pct teme\n");
- for(i = 0; i < 10; i++) {
- printf("Tema %d: ", i+1);
- scanf("%d", &s.pt[i]);
- }
- fflush(stdin);
- printf("Pct examen: "); fgets(s.pe, sizeof(s.pe), stdin);
- fwrite(&s, sizeof(Student), 1, f);
- fflush(stdin);
- printf("Nr. mat: "); scanf("%d", &s.nr);
- }
- fclose(f);
- BinInText(s1, s2, s);
- }
Add Comment
Please, Sign In to add comment