Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. struct para {
  5.     int nr_indeksu;
  6.     char nazwisko[30];
  7.     float ocena;
  8.     struct para *nast;
  9. };
  10. int main(){
  11.     struct para *head=NULL, *ptr=NULL, *ptr2=NULL;
  12.     //struct para data;
  13.     FILE *f;
  14.     int i=0;
  15.     char inputfile[35];
  16.     char outputfile[35];
  17.     int tmp1;
  18.     printf("Podaj nazwe pliku tekstowego:\n");
  19.     scanf("%s", inputfile);
  20.     f = fopen(inputfile, "r");
  21.     if (f == NULL){
  22.         printf("Nie znaleziono pliku!\n");
  23.         return 0;
  24.     }
  25.     if(fscanf(f, "%s", &tmp1)!=1){
  26.         printf("Plik jest pusty\n");
  27.         return 0;
  28.     }
  29.     rewind(f);
  30.     while(!feof(f)){
  31.         if (head==NULL){
  32.             head=ptr=(struct para*)malloc(sizeof(struct para*));
  33.             if (ptr== NULL){
  34.                 printf("Blad przydzialu pamieci!\nKoniec programu!\n");
  35.                 return 0;
  36.             }
  37.             fscanf(f, "%d %s %f", &ptr->nr_indeksu, &ptr->nazwisko, &ptr->ocena);
  38.             head->nast=NULL;
  39.             ptr=head;
  40.         }
  41.         else{
  42.             ptr->nast=(struct para*)malloc(sizeof(struct para*));
  43.             ptr=ptr->nast;
  44.             if (ptr== NULL){
  45.                 printf("Blad przydzialu pamieci!\nKoniec programu!\n");
  46.                 return 0;
  47.             }
  48.             fscanf(f, "%d %s %f", &ptr->nr_indeksu, &ptr->nazwisko, &ptr->ocena);
  49.             printf("%d\t%s\t%f\n", &ptr->nr_indeksu, &ptr->nazwisko, &ptr->ocena);
  50.             ptr->nast=NULL;
  51.         }
  52.         /*fscanf(f, "%d %s %f", &tab1[i].nr_indeksu, &tab1[i].nazwisko, &tab1[i].ocena);
  53.         printf("%d %s %.1f\n", tab1[i].nr_indeksu, tab1[i].nazwisko, tab1[i].ocena);*/
  54.     }
  55.     fclose(f);
  56.     printf("\n\nOsoby z ocena nizsza niz 4.0:\n");
  57.     ptr=head;
  58.     while(ptr->nast!=NULL){
  59.         if (ptr->ocena<4.0)
  60.             printf("%d %s %.1f\n", ptr->nr_indeksu, ptr->nazwisko, ptr->ocena);
  61.     }
  62.     printf("Podaj nazwe pliku wynikowego:\n");
  63.     scanf("%s", outputfile);
  64.     f = fopen(outputfile, "w");
  65.     while(ptr->nast!=NULL){
  66.         fprintf(f, "%i %s %.1lf\n", ptr->nr_indeksu, ptr->nazwisko, ptr->ocena);
  67.     }
  68.     fclose(f);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement