Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Compilation problems??
On Sun, 24 Aug 1997 15:02:14 GMT,
phaywood_at_aardvark.apana.org.au.STOP.SPAM (Peter "Shaggy" Haywood)
wrote:
Hello "Shaggy"
> Here's what you should have after fixing the points I've mentioned:
>
>#include <stdlib.h>
>#include <stdio.h>
>
>char *checkvalue(void); /* prototype the function */
>
>int main(void)
>{
> char *ls_returnvalue;
>
> ls_returnvalue = checkvalue ();
> printf("ls_returnvalue is: %s\n", ls_returnvalue);
>
> return 0;
>}
>
>char *checkvalue(void)
>{
> char *ls_getvalue;
> int li_valid;
>
> ls_getvalue = (char*) malloc(80);
> if(NULL == ls_getvalue)
> {
> printf("Allocation error!\n");
> return NULL;
> }
>
> scanf("%s\n", ls_getvalue);
>
> li_valid = 0;
There is something wrong. You are assigning
0 to li_valid and then in the following statement
using a if statement to check if it is 0. Since
the if statment expression will always be true,
the statement will always be executed.
>
> if (li_valid == 0)
> {
> printf("ls_getvalue is: %s\n", ls_getvalue);
> free (ls_getvalue);
> ls_getvalue = NULL;
> }
Since the statement is always executed, the
function will always return NULL.
>
> return ls_getvalue;
>}
Al Bowers
Tampa, FL
mailto: abowers_at_combase.com
http://www.gate.net/~abowers/index.html
Received on Sun Aug 24 1997 - 00:00:00 CDT
![]() |
![]() |