Advertisement
10rch

Untitled

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