0

I've been banging my head against a wall here for days, trying to print initials after user name input. The errors change continually and are many. I'm trying to name the string array 'name' then iterate through it.

int main(void) { char x, y;

do
{
    printf("What is your name?\n"); // prompts user for name input
    name = GetString(); //store string in array name 'name' 
}
while (char name[i]) != char; //checks user hasn't added integers

i = char name[i];

x = name[0]; //name the character at position 0 in the namelen array 'x' so that it can be printed later

for (i=0; i<strlen(name); i++) //iterates along the length of the string to the end
{

    if (isspace(name[])  
    {
        char isspace(char [y]);
        y ++; //select next character after space and allocates variable name 'y' (so it can be printed later)
    }

}

toupper(x); toupper(y);

printf("%c%c\n", x,y);

}

1 Answer 1

1

the isspace function should return a boolean, whereas you assign a char to the 'return value' of isspace. What you probably want to do is to check if, for every i, the current name[i] is a space, and then store name[i+1] (probably the initial) in some string or char for the initials.

y++ takes the value of y and adds one. Because y is a char, thus an ascii number, it will move the current value of y and increment one, making for example a c into a d

Also not too sure why while (char name[i]) != char; would check for integer input..

Hope that helps!

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .