I'm a new C language learner and I have a problem below, I tried to print name out but it did not print. This is what I tried:
#include <stdio.h>
#include <ctype.h>
int main()
{
char name;
int len = 0;
printf("Enter the user name: ");
name = getchar();
while (name != '\n')
{
len++;
name = getchar();
}
printf("char = %d\n", len);
printf("name = ");
putchar(name);
return (0);
}
output:
Enter the user name: abcd
len = 4
name =
it should print out name = abcd
.
I appreciate that and thank you!
Learn about the concept of array in C first.
Use
scanf()
andprintf()
like below: