Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- void stampaPrimoInFile (FILE *F, char lettera);
- int main()
- {
- FILE *lota;
- char lettera;
- lota=fopen("testo.txt", "r");
- printf("inserisci parola da stampare\n");
- scanf("%c", &lettera);
- stampaPrimoInFile(lota,lettera);
- fclose(lota);
- return 0;
- }
- void stampaPrimoInFile (FILE *F, char lettera)
- {
- int count=0, cnt=0,ar=0;
- char ch, *lol;
- while(1)
- {
- if(ch==EOF)break;
- ch=getc(F);
- count++;
- }
- lol=malloc(sizeof(char)*count);
- rewind(F);
- while(1)
- {
- ch=getc(F);
- lol[cnt]=ch;
- if(lol[cnt]==lettera)
- {
- while(1)
- {
- if(ch=='\n'|| ch==' '|| ch=='.') break;
- lol[ar]=ch;
- ch=getc(F);
- ar++;
- }
- for(cnt=0;cnt<ar;cnt++)
- printf("%c",lol[cnt]);
- break;
- }
- cnt++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement