HP C/iX Library Reference Manual (30026-90004)
196 Chapter5
HP C/iX Library Function Descriptions
getchar
modify data before passing it on). For example, the following program puts parentheses
around each vowel encountered in the input:
#include <stdio.h>
main()
{
int c;
while((c = getchar()) != '\n') {
if(vowel(c)) {
putchar('(');
putchar(c);
putchar(')');
}else
putchar(c);
}
}
vowel(c)
char c;
{
switch(c) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
return (1);
default:
return (0);
}
}
The vowel test is placed in the function vowel; the program terminates when it encounters
a new line.
The getc and putc functions can behave exactly like the getchar and putchar functions
by specifying the appropriate file pointer. For example,
getc(stdin);
is identical to
getchar();
and
putc(c, stdout);
is identical to
putchar(c);