Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct para {
- int nr_indeksu;
- char nazwisko[30];
- float ocena;
- struct para *nast;
- };
- int main(){
- struct para *head=NULL, *ptr=NULL, *ptr2=NULL;
- //struct para data;
- FILE *f;
- int i=0;
- char inputfile[35];
- char outputfile[35];
- int tmp1;
- printf("Podaj nazwe pliku tekstowego:\n");
- scanf("%s", inputfile);
- f = fopen(inputfile, "r");
- if (f == NULL){
- printf("Nie znaleziono pliku!\n");
- return 0;
- }
- if(fscanf(f, "%s", &tmp1)!=1){
- printf("Plik jest pusty\n");
- return 0;
- }
- rewind(f);
- while(!feof(f)){
- if (head==NULL){
- head=ptr=(struct para*)malloc(sizeof(struct para*));
- if (ptr== NULL){
- printf("Blad przydzialu pamieci!\nKoniec programu!\n");
- return 0;
- }
- fscanf(f, "%d %s %f", &ptr->nr_indeksu, &ptr->nazwisko, &ptr->ocena);
- head->nast=NULL;
- ptr=head;
- }
- else{
- ptr->nast=(struct para*)malloc(sizeof(struct para*));
- ptr=ptr->nast;
- if (ptr== NULL){
- printf("Blad przydzialu pamieci!\nKoniec programu!\n");
- return 0;
- }
- fscanf(f, "%d %s %f", &ptr->nr_indeksu, &ptr->nazwisko, &ptr->ocena);
- printf("%d\t%s\t%f\n", &ptr->nr_indeksu, &ptr->nazwisko, &ptr->ocena);
- ptr->nast=NULL;
- }
- /*fscanf(f, "%d %s %f", &tab1[i].nr_indeksu, &tab1[i].nazwisko, &tab1[i].ocena);
- printf("%d %s %.1f\n", tab1[i].nr_indeksu, tab1[i].nazwisko, tab1[i].ocena);*/
- }
- fclose(f);
- printf("\n\nOsoby z ocena nizsza niz 4.0:\n");
- ptr=head;
- while(ptr->nast!=NULL){
- if (ptr->ocena<4.0)
- printf("%d %s %.1f\n", ptr->nr_indeksu, ptr->nazwisko, ptr->ocena);
- }
- printf("Podaj nazwe pliku wynikowego:\n");
- scanf("%s", outputfile);
- f = fopen(outputfile, "w");
- while(ptr->nast!=NULL){
- fprintf(f, "%i %s %.1lf\n", ptr->nr_indeksu, ptr->nazwisko, ptr->ocena);
- }
- fclose(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement