Hello, guys.
I really need some help. To say that programming is akin to magic to me would be an understatement, so forgive this (probably) stupid question of mine.
I wanted to try out the "toupper" function in C and my plan was to write a simple program that would change the case of my input from lowercase to uppercase.
Everything seemed to be ok. But I have run into problem that I cannot solve: the program I wrote stops working when facing a space character in my input. I don't know what I can do about it. Really. I've tried "isspace" fuction, but the result is the same. The only word that gets transformed is the one before the first space. The rest of the input is lost.
I would appreciate very much if you could point out where my mistake is and what I am supposed to do to fix it.
This is my code:
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>


int main(void)
{
    char message[25];
    printf("What is your message to the world?\n");
    scanf("%s", message);
    
    for(int i = 0, n = strlen(message); i < n; i++)
    {
        if(isalpha(message[i]))
        {
            if(islower(message[i]))
            {
                printf("%c", toupper(message[i]));
            }
            else
            {
                printf("%c", message[i]);
            }
        }
        else
        {
            printf("%c", message[i]);
        }
    }
    return 0;
}
I really can't understand why the very first space terminates the program. If I replace them with some random characters, then everything seems to be working just fine.
Thanks!