Advertisement
Extremum

Ex23

Mar 13th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int number(int num);
  4.  
  5. int main()
  6. {
  7.    system("color F0");
  8.    int num,i;
  9.    printf("Input number if you want to count:\nspace-1 \ntabulations-2 \nlines-3\n");
  10.    scanf("%d",&num);
  11.   if(num<1 || num>3){
  12.    printf("Error,please enter number between 1 and 3\n");
  13.    scanf("%d",&num);
  14.   }
  15.   if(num<=2){
  16.    i=number(num);
  17.    printf("in total %d\n",i);
  18.   }
  19.   if(num=3){
  20.     i=number(num);
  21.     printf("%d\n",i-1 );
  22.   }
  23. }
  24.  
  25. int number(int num)
  26. {
  27.   int c,amount=0;
  28.   while((c=getchar())!=EOF){
  29.     if(num==1){
  30.         if(c==' '){
  31.             ++amount;
  32.         }
  33.     }
  34.     if(num==2){
  35.         if(c=='\t'){
  36.             ++amount;
  37.         }
  38.     }
  39.     if(num==3){
  40.         if(c=='\n'){
  41.             ++amount;
  42.  
  43.         }
  44.     }
  45.   }
  46.   return amount;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement