Advertisement
danpalol

traccia 2 esercizio 2

Jun 29th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. void stampaPrimoInFile (FILE *F, char lettera);
  5.  
  6.  
  7. int main()
  8. {
  9.     FILE *lota;
  10.     char lettera;
  11.     lota=fopen("testo.txt", "r");
  12.    
  13.     printf("inserisci parola da stampare\n");
  14.     scanf("%c", &lettera);
  15.     stampaPrimoInFile(lota,lettera);
  16.     fclose(lota);
  17.     return 0;
  18. }
  19.  
  20. void stampaPrimoInFile (FILE *F, char lettera)
  21. {
  22.     int count=0, cnt=0,ar=0;
  23.     char ch, *lol;
  24.     while(1)
  25.     {
  26.         if(ch==EOF)break;
  27.         ch=getc(F);
  28.         count++;
  29.     }
  30.     lol=malloc(sizeof(char)*count);
  31.     rewind(F);
  32.     while(1)
  33.     {
  34.         ch=getc(F);
  35.         lol[cnt]=ch;
  36.         if(lol[cnt]==lettera)
  37.         {
  38.             while(1)
  39.             {
  40.             if(ch=='\n'|| ch==' '|| ch=='.') break;
  41.             lol[ar]=ch;
  42.             ch=getc(F);
  43.             ar++;
  44.             }
  45.             for(cnt=0;cnt<ar;cnt++)
  46.             printf("%c",lol[cnt]);
  47.             break;
  48.             }
  49.         cnt++;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement