I have a simple program that accepts user input of first and last names. . Input is terminated if "blank/empty" string is entered The names are concatenated.
The output prints however many first and last names.
After the program prints however many names, there are several lines of junk as if the loop still running.
If there a way to set output loop equal to the input loop?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{//start of main function
char firstName[50] = "";
char lastName[50] = "";
char catName[50][50];
int i = 0;
int j = 0;
int INPUT = 50;
int OUTPUT[INPUT] = 50;
for (i = 0; i < INPUT; i++){
printf("Please enter first name\n");
gets(firstName);
if(strcmp(firstName, "")==0){
break;
}
printf("Please enter last name\n");
gets(lastName);
strcat(firstName, " ");
strcat(firstName,lastName);
strcpy(catName[i], firstName);
}
for (i = 0; i < OUTPUT; ++i) {
printf("%s\n",catName[i]);
}
system("pause");
return 0;
}//end of main function.