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: Mark Brown <M.A.Brown-4_at_sms.ed.ac.uk>
Date: 1997/08/14
Message-ID: <m3pvrhv8v2.fsf@unknown.localdomain>#1/1

Programming <sysdev_at_mb.sympatico.ca> writes:

> #include "stdio.h"

It is more usual to use <> rather than "" for standard headers.

> int main()
> {
 

> char *ls_returnvalue;
 

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

You don't have a prototype for checkvalue(). Your compiler assumes that functions without prototypes return int - and you are trying to assign an int to a char *.

> exit(0);

Or return 0, whichever you prefer.

> } /********** end main ************/
 

> char *checkvalue() /*line 96 */

Previously, you used checkvalue without a prototype - now the compiler has 'learned' it returns an int, but you're telling it what you really meant and it gets confused. Either move this definition about main(), or include the line

char *checkvalue(void);

before main().

> {
>
> char *ls_getvalue;
> int li_valid;
 

> ls_getvalue = (char*) malloc(80);

The cast on malloc() is not needed, and hides an error. Since you haven't included stdlib.h, there is no prototype for malloc(). As above, it defaults to returning an int. The only reason you don't get an error or warning is the cast.

> scanf("%s\n", ls_getvalue);

scanf() is a very dangerous function to use in production code. It is very intolerant of errors. See the comp.lang.c FAQ for more information. The FAQ can be ftped from rtfm.mit.edu in pub/usenet/comp.lang.c/ and found on the web at http://www.eskimo.com/~scs/C-faq/top.html .

> li_valid = 0;

Have you removed some code here?

> if (li_valid == 0)

This will *always* be true unless there is code between here and the assignment above.

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

You aren't actually returning anything from the function.

>
> } /************ end checkvalue ****************/
>
 

> The same errors also occur if I copy everything to char2.c, and compile with:
> cc char2.c

So they should! The filename ought to have no bearing on anything except __FILE__.

(followups set to comp.lang.c)

-- 
Mark Brown  mailto:M.A.Brown-4_at_sms.ed.ac.uk  (Trying to avoid grumpiness)
            http://www.geocities.com/SiliconValley/Lakes/7537/
Received on Thu Aug 14 1997 - 00:00:00 CDT

Original text of this message

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