I have been struggling to print my full name in the C language from past several days. After several tries this is what I came up with.
#include <stdio.h>
int main(void)
{
char yourname[20];
int yourage;
char initial;
printf("Whats your name? ");
scanf("%18[^\n]s", yourname);
printf("And your initial is? ");
scanf("%c", &initial);
yourname[19] = '\0';
fflush(stdin);
printf("How old are you? ");
scanf(" %d",&yourage);
printf("Your name is %s %c and you are %i years old.\n", yourname,
initial, yourage);
return(0);
}
When I compile and run the program, this is what I get. I am compiling with full warning turned on like so
make name
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -
std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow name.c -lcrypt -
-lm -o name
Please help..
Whats your name? Alokananda
And your initial is? How old are you? 35
Your name is Alokananda
and you are 35 years old.