Problem: If only one word is inserted, only output one word
Hello all, this is a portion to a larger program i'm working on. Basically if one string is inserted, i would like printf to output the one string. Currently scanf is hanging. I was wondering about this line:Code:#include <string.h> #include <stdio.h> #include <stdlib.h> int main(void) { char my_string[15]; char my_string_2[15]; char empty[1] = ""; printf("> "); // If only one word is inserted, only output one word int i = 1; do { scanf("%s %s", my_string, my_string_2); if(strcmp(my_string_2, empty) == 0) { printf("You inserted one string: %s\n", my_string); } else { printf("You inserted two strings\n"); } } while(i == 1); return 0; }
I've tried it without the quotes, also adusting array size. Also this line:Code:char empty[1] = ""
I've tried using != in the strcmp function as well as < 1 and > 1 without any luck. I also I have a question, would it be possible to include '\0' or '\n' in the strcmp function.Code:if(strcmp(my_string_2, empty) == 0)