My exercise was:
Write a program that reads input as a stream of characters until encountering EOF. Have the program print each input character and its ASCII decimal value. Note that characters preceding the space character in the ASCII sequence are nonprinting characters. Treat them specially. If the nonprinting character is a newline or tab, print \n or \t, respectively. Print 10 pairs per line, except start a fresh line each time a newline character is encountered.
This is my code (regarding the special characters i defined only \n and \t):
#include <stdio.h>
int special_chars(int ch);
int main(void)
{
int x;
printf("please enter a some characters, and ctrl + d to quit\n");
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;
}
Is it Ok..? tnx

printf("%c,%d ", ch, ch);%c is expecting a char while %d an int. While ch is always an int. – Loki Astari Feb 1 at 19:12