Hello, I am trying to create a program that asks the user to input a first and last name and then outputs it in the following format:
George Washington
Washington, G.
Here is what I have; it won't print the last name when I run it.
Code:
#include<stdio.h>
int main(void)
{
int i; /*indexing integer*/
char last[50]; /*two seperate arrays to hold char strings*/
char name[50];
printf("Enter a first and last name: \n\n");
fgets(name, sizeof name, stdin); /*better than scanf*/
for(i=0; i<' '; i++) /*loop until space*/
{
for(i=' ';i<='\0';i++) /*loop after space*/
{
name[i>' ']=(char)last[i>' ']; /*define part of name to be last*/
}
}
printf("%s,%c.",last,name[0]); /*attempt to print as described*/
return 0;
} /*the code doesn't print the last name*/