id password check | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

id password check

This problem is about checking id and password. I think I did well on my code. But there was compile error. could you help me with the code? https://code.sololearn.com/czhX038QCpa6/#c

2nd Jun 2019, 5:22 AM
김도현
김도현 - avatar
1 Answer
+ 2
You did well, it's close to what you want. The exception here is that you tried to assign strings to a _char_ instead of a char pointer or a char array. You want ID and PW to be: const char *ID = "galaxy storm"; const char *PW = "norara"; The other issue is with the variable 'I' and 'W' which are also just a single char. I'd turn those into: char I[32]; char W[32]; Using scanf() for strings is problematic so I'd recommend: fgets(I, sizeof(I), stdin); fgets(W, sizeof(W), stdin); I'm guessing you already tried the above and the comparisons failed. The reason being that fgets() adds the newline character to the string so strcmp() will never return a match. To remove the newlines the easiest way is to type: I[strlen(I)-1] = '\0' W[strlen(W)-1] = '\0'; After that, it should work as expected.
2nd Jun 2019, 6:48 AM
Cluck'n'Coder
Cluck'n'Coder - avatar