Re: Error in function declaration
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Wed, 11 Apr 2007 18:40:40 -0700
On 11 Apr 2007 07:02:27 -0700, "nick048" <nicosia.gaetano@xxxxxxxxxxx>
wrote:
Hi
In the main I have declared a variable
char string[100];
I need to construct this variable with a function and I have written
the code:
char stringReceived(int sockDesc){
char unsigned c;
char tmp[100] = " ";
int i=0;
int n;
do {
n = recv(sockDesc, &c, 1, 0); // this function exist for
client/server dialog and is not rilevant for my problem
if (c!='\n'){
tmp[i]=c;
i++;}
} while( c!='\n' );
tmp[i]='\0';
return(tmp);
return is a statement, not a function. The parentheses are
superfluous.
In this context, the expression tmp will evaluate to the address of
tmp[0] with type char*.
1 - This is inconsistent with the return type specified at the
start of the function definition.
2 - Even if you change the function's return type, tmp will cease
to exist as soon as the function exits. While it is not illegal to
return the value of a no-longer-existing object, it is illegal for the
calling function to do anything with that address. Technically, the
address becomes indeterminate.
}
In the main I call:
string = stringReceived(nSocketDesc);
If you really defined string as an array as you claimed at the
beginning of the post, this would require a diagnostic since an array
name cannot appear on the left of the assignment operator.
Maybe you would like to show us the real code.
When I compile the program, this error is returned:
incompatible types assignement in function stringReceived and the line
number is the call.
Sure I mistake the declaration of function, but i don't be able to
correct the problem.
Remove del for email
.
- References:
- Error in function declaration
- From: nick048
- Error in function declaration
- Prev by Date: Re: char pointers?
- Next by Date: Re: char pointers?
- Previous by thread: Re: Error in function declaration
- Next by thread: Re: Error in function declaration
- Index(es):
Relevant Pages
|