ahhh where did i mess up???

0 Maneh Clovis · May 15, 2015
This progam has to ask a user to enter a name then print the first three characters. But it prints only the first.

#include <stdio.h>
#include <math.h>
int main()
{
    char name[7];
    
    printf("enter you name: ");

    scanf("%c",name);

    printf("\n first letter is %c \n ",name[0]);

    printf("second is %c \n",name[1]);

    printf("and the third is %c ",name[2]);
 return 0;
}



Post a Reply

Replies

Oldest  Newest  Rating
+1 c student · May 15, 2015
because you've only specified to scan in one character:
scanf("%c",name);   /* should be %s instead of %c */
0 Maneh Clovis · May 19, 2015
THANKS IT WORKED.
  • 1

C

107,188 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator