Click here to Skip to main content
15,892,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The array should store the first and last name of 5 users separated by a space .
This is what I did so far .

What I have tried:

#include <stdio.h>

int main()
{
    char username[5][25];   
    int i;
    for(i=0;i<5;i++){
    printf("Enter your full name : ");
    scanf("%s",username[i]);
    printf(" \n Your full name is %s : ",username[i]);
    }
    
}
Posted
Updated 12-Dec-21 1:51am
v2
Comments
Richard MacCutchan 12-Dec-21 7:54am    
You should enter the two parts of the name separately and combine them before adding to the array.

1 solution

scanf always stops at the first whitespace character.
To read the whole name including spaces, use fgets:@
C
#include <stdio.h>

int main()
{
    char username[5][25];   
    int i;
    for(i=0;i<5;i++)
    {
        printf("Enter your full name : ");
        fgets(username[i], 25, stdin);
        printf(" \n Your full name is %s : ",username[i]);
    }
}
 
Share this answer
 
Comments
CPallini 12-Dec-21 10:08am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900