Mega Code Archive

 
Categories / C / Code Snippets
 

Reading a string with gets()

#include <stdio.h> void main() { char initial[2] = { 0 }; char name[80] = { 0 }; printf("Your first initial: "); gets(initial); printf("Your name: " ); gets(name); if(initial[0] != name[0]) printf("\n%s,you got your initial wrong.\n", name); else printf("\nHi, %s. Your initial is correct. Well done!\n", name); }