Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Compilation problems??

Re: Compilation problems??

From: GAZZA <sturgess_at_ccis.adisys.com.au>
Date: 1997/08/14
Message-ID: <33F33A83.4E0E@ccis.adisys.com.au>#1/1

> It is strange, because I have specifically
> defined the return value of the function as a
> pointer to char. Yet, the error message is
> saying that the return value is an int!

Yes, this is because you call the function before you define it (line 86 precedes line 96). This means that the compiler decides that the function must return an int (the default return type for functions in C).

This can be solved with a prototype:

> #include "stdio.h"

Should probably be

#include <stdio.h>

Here you need to insert:

char *checkvalue(void);

> int main()

int main(void)
> {
>
> char *ls_returnvalue;
>
> ls_returnvalue = "";

In effect, this does nothing, since on the very next line you re-assign the value of the pointer. This could be safely omitted.

> ls_returnvalue = checkvalue (); /* line 86 */

This will work now.

> printf("ls_returnvalue is: %s\n", ls_returnvalue);
>
> exit(0);

The standard allows exit to return EXIT_SUCCESS or EXIT_FAILURE, both of which are defined in stdlib.h; personally, I would simply change this to:

return 0;

> } /********** end main ************/
>
> char *checkvalue() /*line 96 */

Here,

char *checkvalue(void)

is better style (IMHO).

> {
>
> char *ls_getvalue;
> int li_valid;
>
> ls_getvalue = (char*) malloc(80);
> scanf("%s\n", ls_getvalue);

scanf is a bad function to use for user input. You'd be better off with fgets followed by sscanf.

> li_valid = 0;
>
> if (li_valid == 0)
> {
> printf("ls_getvalue is: %s\n", ls_getvalue);
> free (ls_getvalue);
> ls_getvalue = 0;
> } /* end if */

You should return something here. I'm assuming that you've trimmed part of the code; this doesn't seem to do anything useful.
>
> } /************ end checkvalue ****************/

Hope that helps.

-- 
"If you can't stand the chill, get out of the freezer."
GAZZA (mailto:sturgess_at_ccis.adisys.com.au)
Received on Thu Aug 14 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US