Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. int special_chars(int ch);
  3.  
  4. int main(void)
  5.  
  6. {
  7. int x;
  8. printf("please enter a some characters, and ctrl + d to quitn");
  9.  
  10. special_chars(x);
  11.  
  12. return 0;
  13. }
  14.  
  15. int special_chars(int ch)
  16.  
  17. {
  18. int pairsNum = 0;
  19.  
  20. while ((ch = getchar()) != EOF)// testing charecters while not end of file.
  21. {
  22.  
  23. if (ch == 'n')// testing if a control charecter, and printing its
  24. {
  25. printf("\n ");
  26. pairsNum++;
  27. }
  28.  
  29. else if (ch == 't')
  30. {
  31. printf("\t ");
  32. pairsNum++;
  33. }
  34.  
  35. else
  36. {
  37. printf("%c,%d ", ch, ch);
  38. pairsNum++;
  39. }
  40.  
  41. if (pairsNum == 10)// counting the number of outputs, and printing a newline when is 10 (limit).
  42. printf("n");
  43. }
  44. return ch;
  45. }
  46.  
  47. $ cat x
  48. abcdefgh
  49. ijklmnop
  50. qrstuvwxyz
  51.  
  52. $./program < x
  53. please enter a some characters, and ctrl + d to quit
  54. a,97 b,98 c,99 d,100 e,101 f,102 g,103 h,104 n i,105
  55. j,106 k,107 l,108 m,109 n,110 o,111 p,112 n q,113 r,114 s,115 t,116 u,117 v,118 w,119 x,120 y,121 z,122 n $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement