C: How can I redesign the program so that I can answer "Yes" instead of "Y"?
I now have this code:
int main() { char wand[2]; do { printf("Ist die Wand da? (Ja | Nein)\n"); scanf("%s", wand); } while (wand[0] != 'y' && wand[0] != 'Y'); printf("Drehung\n"); printf("Schritt!!\n");
But I'd like to answer yes instead of Y. How do I do that?
Hello Daniel,
Don’t let yourself be on any grumpy “experts” that throw anything into the room and don’t show a centimeter of understanding for beginners.
here is a snippet which should clarify your actual question:
However, there is the problem that “char wand[2]” has only space for a single character and no zero-byte. So if you try to read a string with two characters like “Yes” into this array, the zero-byte is written outside the array, which can lead to errors.
Please also change the “char wand[2]” to “char wand[4]”
I also ask you that if you have serious intentions to learn a programming language, that you also think about what you actually want to achieve with it. All programming languages are good for a bit. In addition, I can see from your comments that you have little understanding of what you ask us. Oriente to any Youtube playlists, books or w3school.
Have fun!
You make the array “wall” sufficiently large (complete zero character note) and then compare the string with strncmp.
Could you write that maybe in the code? do not really understand
What don’t you understand?
Like “he”? You can write any of the functions you have.
You okay?
As many as are written.
How many function are there in c?
You’ll make it big enough by giving a proper greeting to the array’s defionition.
strncmp is a library function. See:
https://pubs.opengroup.org/onlinepubs/000095399/functions/strncmp.html
How I make it sufficiently large and by strncmp I have never heard anything :/