I'm trying to make a simple memory for username and phone number so the user could refer back to it at the end of the big chunk of code, but the string stored in name1 seems to be lost when printing it out again:
// Online C compiler to run C program online
#include <stdio.h>
#include <string.h>
//Intialisation
int main() {
// Write C code here
char name1[30], name2[30], phonenumber[30], final
int userdetailchecker = 2;
int finalconfirmation = 0;
printf("\n\n******GMI KOPERASI ORDER AND SELF-PICK-UP SERVICE******\n");
printf("|You have to register your details to access this service|\n");
while(userdetailchecker != 1){
printf("Please enter your first name: ");
scanf("%s", name1);
printf("Please enter your last Name: ");
scanf("%s", name2);
strcat(name1," ");
strcat(name1, name2);
printf("Is your name %s?\n1.Yes\n2.No\n", name1);
scanf("%d", &userdetailchecker);
}
printf("Great! Your orders would be associated with the username %s", name1);
printf("\nPlease enter your phone number: ");
scanf("%s", phonenumber);
while(strlen(phonenumber) < 9 || strlen(phonenumber) > 13){
printf("Invalid phone number(Must be 9 to 13 digits only)");
printf("\nPlease enter your phone number: ");
scanf("%s", phonenumber);
}
printf("You have successfully registered your phone number! (%s)", phonenumber);
printf("\n\nHello user %s!\n", name1);
printf("Continue to end section? y/n?\n");
char check[3];
scanf("%s", check);
if(strcmp(check, "yes") == 0)
{
printf("\nPlease confirm your user details");
printf("\nUsername = %s", name1);
printf("\nPhone number = %s", phonenumber);
printf("\n1.Yes\n2.No\n");
while(1){
scanf("%d", &finalconfirmation);
if(finalconfirmation == 2)
{
printf("Please log out of this session.");
break;
}
}
}
else{
return 0;
}
return 0;
}
I've been at it for a while now; to no avail. Would appreciate help and tips