I am writing a simple program in C to assign two separate user inputs to separate arrays, and then concatenating the arrays.
However, I have found that if a space is included in the user-inputted string one word is assigned to array 1, and the other to array 2. My code is below.
char str1[SIZE];
char str2[SIZE];
char str3[SIZE2];
printf("Enter a string: ");
scanf("%s", str1);
printf("\nEnter another: ");
scanf("%s", str2);
printf("\n\nInput 1: %s\n", str1);
printf("Input 2: %s\n", str2);
As can be seen, if a space is input in the first scanf() the second scanf() is 'skipped' and the words are sparated into str1[] and str2[]. I am wondering what is causing this and is there a more elegant way of accomplishing my goal?
SIZE is defined as 50 and SIZE2 as 100