Solution for Exercise 17-6
ex1706
#include <stdio.h>
int main()
{
char input[64];
int ch;
int x = 0;
printf("Type in some text: ");
fgets(input,63,stdin);
while(input[x] != '\n')
{
ch = input[x] & 223;
putchar(ch);
x++;
}
putchar('\n');
return(0);
}
Output
Type in some text: this is a test
THIS IS A TEST
Notes
* The output on a Macintosh looks like this:
This could be due to the character set used by the terminal. On a PC, ASCII code 0 may display as a space, whereas on a Mac it doesn't display at all. Typing in non-alpha characters has a similar effect:
The strange codes are due to the effect the bitwise-AND mask has on the character's ASCII code.
* The ASCII code for the space character is 32. If you run the solution from Exercise 17-5 using that value, here is what you see for output:
The result of the 223 AND mask on the space character is to change its code to zero.
Copyright © 1997-2025 by QPBC.
All rights reserved
