Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int special_chars(int ch);
- int main(void)
- {
- int x;
- printf("please enter a some characters, and ctrl + d to quitn");
- special_chars(x);
- return 0;
- }
- int special_chars(int ch)
- {
- int pairsNum = 0;
- while ((ch = getchar()) != EOF)// testing charecters while not end of file.
- {
- if (ch == 'n')// testing if a control charecter, and printing its
- {
- printf("\n ");
- pairsNum++;
- }
- else if (ch == 't')
- {
- printf("\t ");
- pairsNum++;
- }
- else
- {
- printf("%c,%d ", ch, ch);
- pairsNum++;
- }
- if (pairsNum == 10)// counting the number of outputs, and printing a newline when is 10 (limit).
- printf("n");
- }
- return ch;
- }
- $ cat x
- abcdefgh
- ijklmnop
- qrstuvwxyz
- $./program < x
- please enter a some characters, and ctrl + d to quit
- a,97 b,98 c,99 d,100 e,101 f,102 g,103 h,104 n i,105
- 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