Florii11

2

Jan 4th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. long long f(char*a, char x)
  5. {
  6.     switch (x)
  7.     {
  8.     case 'a':
  9.     {
  10.         return strlen(a);
  11.     }
  12.     case 'b':
  13.     {
  14.         int ct=0;
  15.         for(int i=0; i<strlen(a); i++)
  16.             if(a[i]==' '||a[i]=='\n')
  17.                 ct++;
  18.         return ct+1;
  19.     }
  20.     case 'c':
  21.     {
  22.         int ct=0;
  23.         for(int i=0; i<strlen(a); i++)
  24.             if(a[i]=='\n')
  25.                 ct++;
  26.         return ct+1;
  27.     }
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     FILE* fp=fopen("cuvinte_in.txt","r");
  34.     if(!fp)
  35.         return -1;
  36.     char *a=calloc(1,sizeof(char));
  37.     int i=0;
  38.     while(!feof(fp))
  39.     {
  40.         fscanf(fp,"%c",&a[i++]);
  41.         a=realloc(a,(i+1)*sizeof(char));
  42.     }
  43.     printf("%lld\n",f(a,'a'));
  44.     printf("%lld\n",f(a,'b'));
  45.     printf("%lld\n",f(a,'c'));
  46.  
  47.     fclose(fp);
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment