Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct lista
- {
- char napis[20];
- struct lista *n;
- } element;
- void wpisz(element **pocz, FILE *f);
- void czyt_l(element *pocz);
- int main()
- {
- FILE *f;
- f=fopen("Dane.txt", "rt");
- element *slowa;
- slowa=malloc(sizeof(element));
- wpisz (&slowa, f);
- fclose(f);
- czyt_l(slowa);
- return 0;
- }
- void wpisz(element **slowo, FILE *f)
- {
- char c, w[20];
- element *pom=*slowo;
- //fscanf(f, " %c", &c);
- c=getc(f);
- if(c==EOF)
- {
- *slowo=NULL;
- return;
- }
- while(c!=EOF)
- {
- while(c!='.')
- {
- int j;
- for(j=0;c!=' '&&c!='.'&&c!='\0';j++)
- {
- w[j]=c;
- //fscanf(f, " %c", &c);
- c=getc(f);
- }
- w[j]='\0';
- strcpy(pom->napis, w);
- pom->n=malloc(sizeof(element));
- pom=pom->n;
- }
- }
- pom=NULL;
- }
- void czyt_l(element *slowo)
- {
- int i;
- element *c;
- c=slowo;
- printf("\n");
- if(c==NULL) printf("\nLista pusta!");
- for(i=0; c!=NULL; i++,c=c->n) printf("%d slowo w liscie: %s\n",i+1, c->napis);
- }
Advertisement
Add Comment
Please, Sign In to add comment