I think you're having the same problem that I had, please refer to post
(very recent) with subject: return address of new memory.
It would be better if you posted your code, I'm doing something similar in
my programs, so first I give you that stuff and later I will simply paste
other people's stuff here:
main():
char *grayhistmatchfile = NULL;
char *ihsfile = NULL;
char *ihistmatchfile = NULL;
char *pcfile = NULL;
char *pcmtxfile = NULL;
char *inversepcfile = NULL;
char *graydwtfile = NULL;
ewrm_generateFileNames(&grayhistmatchfile, &ihsfile, &pcfile, &pcmtxfile,
&ihistmatchfile,
&graydwt1file, &graydwt2file, &graydwt3file, &resampledifile,
©a1file, ©a2file, ©a3file,
&mergedihvdfile, &idwt1file, &idwt2file, &idwt3file,
&mergedidwt1file, &mergedidwt2file, &mergedihmfile, &hsresampledfile,
&rgbfile, &pc_xresampledfile, &inversepcfile, &stackoutput,
&lclerr);
void ewrm_generateFileNames(char **grayhistmatchfile, char **ihsfile, char
**pcfile, char **pcmtxfile, char **ihistmatchfile,
char **graydwt1file, char **graydwt2file, char **graydwt3file, char
**resampledifile,
char **copya1file, char **copya2file, char **copya3file,
char **mergedihvdfile, char **idwt1file, char **idwt2file, char
**idwt3file,
char **mergedidwt1file, char **mergedidwt2file, char **mergedihmfile, char
**hsresampledfile,
char **rgbfile, char **pc_xresampledfile, char **inversepcfile, char
**stackoutput,
Eerr_ErrorReport **inerr)
{
You copy to char * in this function, e.g.
*graydwt1file = strcpy(...);
}
************************************************** ***
You are getting confused with levels of indirection. A good rule of
thumb: if you find yourself assigning something to a function parameter
(not to what the parameter points at), then you're on the wrong track.
[color=blue]
> void getWaveletCoeffs(float *ld, float *hd, int *filterLen)[/color]
Change this to:
void getWaveletCoeffs(float **ld, float **hd, int *filterLen)
Why? Because you wish to assign to *pointers* in main(). Therefore
this function needs to receive *pointers to pointers*.
If you wish to assign to "foo type", then your function must receive
"pointers to foo type". This goes for any meaning of "foo type".
[color=blue]
> {
> ld = (float*)malloc(2*SZFLOAT);
> hd = (float*)malloc(2*SZFLOAT);[/color]
Change these to:
*ld = malloc(2*SZFLOAT);
*hd = malloc(2*SZFLOAT);
Note that while your old code assigns to ld and hd themselves, mine
assigns to what they point at. (See the * operator?) This is what I
was talking about earlier.
[color=blue]
> *ld++ = 0.7071;
> *ld-- = 0.7071;[/color]
[color=blue]
> *hd++ = -0.7071;
> *hd-- = 0.7071;[/color]
These also need to be changed, to something like:
**ld = 0.7071;
*(*ld+1) = 0.7071;
**hd = -0.7071;
*(*hd+1) = 0.7071;
If I understood your logic correctly.
--
Pushkar Pradhan
"Peter "Shaggy" Haywood" <phaywood@alphalink.com.au.STOP.SPAM> wrote in
message news:3f61b0ae.6516961@news.alphalink.com.au...[color=blue]
> Groovy hepcat Sona was jivin' on Thu, 11 Sep 2003 22:49:08 +1000 in
> comp.lang.c.
> Please help! char* problems!'s a cool scene! Dig it!
>[color=green]
> >I understand the problem I'm having but am not sure how to fix it. My
> >code passes two char* to a function which reads in some strings from a
> >file and copies the contents into the two char*s. Now when my function
> >returns, the values stored in the char* are some garbage values (perhaps
> >because I didn't allocate any memory for them).. but even if I allocate
> >memory in the function, on the return of this function I see garbage..[/color]
>
> This is a FAQ. Please go to
>
http://www.eskimo.com/~scs/C-faq/top.html and read it. Your question
> (or part of it) is FAQ 4.8.
>
> --
>
> Dig the even newer still, yet more improved, sig!
>
>
http://alphalink.com.au/~phaywood/
> "Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry &[/color]
W. Walker.[color=blue]
> I know it's not "technically correct" English; but since when was rock &[/color]
roll "technically correct"?