Question

I have to make a little c program that converts lowercase letters to uppercase. I have managed to do this, however, it's output is not yet completed. The following is what I made so far:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void){

char s[100];
int i;

gets(s);

for(i = 0; i < strlen(s); ++i)
{
    s[i] = toupper(s[i]);
}

printf (s);

}

If you'd insert 'this is a_test' it's output would be 'THIS IS A_TEST'. However, it should be the following:

'THIS

IS

A_TEST'

How do I do this? Thanks in advance.

Was it helpful?

Solution

for(i = 0; i < strlen(s); ++i) {
    if(s[i] = ' ')
        s[i] = '\n');
    else
        s[i] = toupper(s[i]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top