simple-escape-sequence:
Anytime you need to express any of these 11 characters as a constant in code, use the following:
'\\' (backslash)
'\'' (quote)
'\"' (double quote)
'\?' (question mark)
'\a' (alarm)
'\b' (backspace)
'\f' (form feed)
'\n' (new line)
'\r' (carriage return)
'\t' (horizontal tab)
'\v' (vertical tab)
Good time for code re-use:
int getNumPipe(const char* cmd, char match) {
int num = 0;
while (*cmd != '\0') {
if (*cmd == match) num++;
cmd++;
}
return num;
}
...
char s[100];
fgets(s, sizeof s, stdin);
printf(" \" occurs %d times.\n", getNumPipe(s, '\"'));
printf(" \' occurs %d times.\n", getNumPipe(s, '\''));