Scanning an entry by scanf does not move in the string beyond the blank space

1

I'm trying to make a program that reads a sentence, and then put each word initial in capital letters, if not already. The problem is that I type a sentence but it only returns the first word, nothing more. the word is with the first capital letter but the other words of the phrase do not appear in output .

#include<stdio.h>
#include<ctype.h>
char namechange( char abc[], int size);
int main()
{
    int i,n;
    char name[100000];
    scanf("%s", &name);

    namechange( name, n );

}


char namechange( char abc[], int size)
{
    int i, k = 0;
    for ( i = 0; abc[i] != '
#include<stdio.h>
#include<ctype.h>
char namechange( char abc[], int size);
int main()
{
    int i,n;
    char name[100000];
    scanf("%s", &name);

    namechange( name, n );

}


char namechange( char abc[], int size)
{
    int i, k = 0;
    for ( i = 0; abc[i] != '%pre%'; i ++)
    {
        int a,b;
        a = abc[i];
        b = abc[i - 1];
        if (i == 0 || 'b' == 8)
           abc[i] = toupper (abc[i]);
    }
    while ( abc[k] != '%pre%')
    {
        printf("%c", abc[k]);
        k = k + 1;
    }

    }
'; i ++) { int a,b; a = abc[i]; b = abc[i - 1]; if (i == 0 || 'b' == 8) abc[i] = toupper (abc[i]); } while ( abc[k] != '%pre%') { printf("%c", abc[k]); k = k + 1; } }
    
asked by anonymous 06.03.2017 / 01:42

1 answer

3

This code does not make sense or compile. The main problem is that scanf() interprets spaces improperly, so you need to ask for it to format properly. In fact anything other than simple exercises should not use scanf() .

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

void namechange(char abc[]) {
    for (int i = 0; abc[i] != '
#include<stdio.h>
#include<ctype.h>

void namechange(char abc[]) {
    for (int i = 0; abc[i] != '%pre%'; i++) {
        if (i == 0 || abc[i - 1] == ' ') {
            abc[i] = toupper(abc[i]);
        }
    }
    printf("%s", abc);
}

int main() {
    char name[1000];
    scanf("%[^\n]s", name);
    namechange(name);
}
'; i++) { if (i == 0 || abc[i - 1] == ' ') { abc[i] = toupper(abc[i]); } } printf("%s", abc); } int main() { char name[1000]; scanf("%[^\n]s", name); namechange(name); }

See running on ideone . And at Coding Ground . Also put it on GitHub for future reference .

    
06.03.2017 / 02:02