readchar
-
Hi!
Bin noch ein Anfänger und hab nen kleines Problem.
Ich will eine Funktion schreiben, die ein char Variable einließt (inkl.Fehlerbehandlung)
mein Problem ist, dass ich nicht weiß, wie ich feststellen kann wie groß ans1 bzw. ans2 sind, da es unabhängig sein soll.
Hoffe mir kann da jemand helfen.#include <stdio.h>
int readchar (const char msg[], const char ans1[], const char ans2[])
{
int readout;
char zeichen;printf("%s", msg);
scanf ("%c", &zeichen);if ( zeichen == ans1[0])
readout = 1;
else if ( zeichen == ans2[0])
readout = 2;
else
printf("Eingabefehler!\n");return readout;
}
-
Vielleicht hilft dir http://www.cplusplus.com/ref/cstring/strlen.html weiter
-
Danke, werd ich gleich mal ausprobieren