Can you test this poorly written code that I was marked down for? Is char in string program

Never ever use the gets() function. It has actually been removed from the C standard because it is unsafe. In your case you've given it a buffer capable of holding 99 characters plus the null character (100 total), but what happens if someone types in 200 characters? There's no way for you to tell gets() to only fill 100 characters, and since gets() doesn't know, it will write past the end of the buffer (which is not only undefined behaviour, but the cause of many security issues in software). You can use fgets instead:

fgets(buffer, sizeof buffer, stdin); 

(not that sizeof buffer only works here in this situation when buffer is an array type, such as what you have).

Also, I encourage you to enable all warnings when you compile code, and don't ignore any of them! For GCC and clang, you can enable warnings by providing the switches -Wall -Wextra. I usually use -Werror as well, which means that all warnings are treated as errors (and as such, your code won't compile if there are any warnings).

/r/C_Programming Thread