Greetings, I know it's usually a bad habit to include several questions in a
single message, but they are quite related.
I have declared and defined a function named readin, whose purpose is to get
input from stdin and save the result in a character array (provided the
input does not exceed the maximum limit). Somehow it feels natural that
readin will then have the type "char *" and return the obtained input to
whoever calls it (or rather, the address of the first element?). Such as
this:
char *readin();
However, in case anything goes wrong readin should be able to return an
error code to the function that called it.
I "solved" the problem with the following declaration of readin:
int readin (char *);
Which makes it possible to return -1, and the function that calls readin
always tests the return value in an if-clause. From my brief and
incomprehensible explanation, does this look like an acceptable solution -
or are there better, standardized ways to perform error testing? I'm new to
C and am therefore trying to pick up as few bad habits as possible.