I've searched the forums, and implemented a lot of answers found here, but none of them seem to work entirely.
Here is the code in question:
When I run this and type "this is a test" the printout is "THIS". It only converts the first word of the string. I have tried different variations for the terminating condition of the for loop, but none of them seem to work.Code:#include <stdio.h> #include <strings.h> #include <string.h> #include <ctype.h> int main(int argc, char** argv) { char buf[10]; scanf("%s", &buf); int i; for(i = 0; buf[i] != '\0'; i++) { if(buf[i] >= 'a' && buf[i] <= 'z') buf[i] = toupper(buf[i]); } printf("%s\n",buf); }
Other ways I've tried terminating the for loop:
for( i = 0; buf[ i ]; i++ )
for( i = 0; i < 10; i++ )
Other way I tried changing the case of the char's:
buf[ i ] -= 32;
It seems to be changing the case of the char as it should, but it just stops working on the string after the first word.
This is just a sample program, it is actually part of a project where I have a client program and a server program, and I'm sending a message to the server, where it is changed to all uppercase, then sent back to the client. This "toupper" part of the program is the only part not working. Which is why I'm working on it in a separate little test program.