Re: Cannot return values of char variable
- From: mark_bluemel@xxxxxxxxx
- Date: 3 Nov 2006 02:37:13 -0800
Pedro Pinto wrote:
Hi there once more........
Instead of showing all the code my problem is simple.
OK - so give us a simple testcase.
I've tried to create this function:
char temp(char *string){
alterString(string);
return string;
}
char alterString(char *string){}
temp receives a string and uses the alterString to modify it.
OK - so write a minimal testcase which uses these functions to work
with a string, show us the whole code (cut and paste, don't retype),
tell us what input you gave it, what output you expected and what
output you got. Then we've got something to work on.
Here's the sort of thing I mean (this is just an example, which I
didn't expect to work) :-
#include <stdlib.h>
#include <stdio.h>
char alterString(char *string){}
char temp(char *string){
alterString(string);
return string;
}
int main(void) {
char myString[]="Hello Pedro";
printf("I started with [%s]\n",myString);
printf("I got [%s]\n",temp(myString));
return EXIT_SUCCESS;
}
When I compiled it, I had this warning from gcc:-
pedro.c: In function `temp':
pedro.c:9: warning: return makes integer from pointer without a
cast
When I ran it, this happened:-
./pedro
I started with [Hello Pedro]
Segmentation fault
Which is fair - temp() returns a char, not a char *, but I told printf
to treat it as the address of (the first of) a null-terminated set of
characters.
I think part of your problem is that temp() and alterString() should be
declared as returning char *, not char, but beyond that - who knows?
.
- References:
- Cannot return values of char variable
- From: Pedro Pinto
- Cannot return values of char variable
- Prev by Date: Re: get the address of a function??
- Next by Date: Re: Cannot return values of char variable
- Previous by thread: Re: Cannot return values of char variable
- Next by thread: Re: Cannot return values of char variable
- Index(es):
Relevant Pages
|
|