S
srikar2097
I have written this small fn. to strip down whitespaces ("\n") a given
string (only leading and trailing).
The program itself might not be foolproof but that is not my concern
right now. When I compile this
I get a warning :--
"string_utils.c:96: warning: function returns address of local
variable.
I have declared the fn. as fn. pointer and this fn. returns the
address of a string array. Why does
the compiler give out this warning? Please help.
Thanks,
Srikar
PROGRAM:
--------------
char *xstrip(char *); //declaration.
char *xstrip(char *c)
{
int i=0;
char tmp_str[xstrlen(&c[0])];
while(*c != '\0')
{
if(*c==32) // if space.
{
if((*(c+1)!=32 && *(c-1)!=32))
;
else
{
c++;
continue;
}
}
tmp_str=*c;
i++;
c++;
}
//Adding null char to indicate end of string. Else printf would
not know where str ends.
tmp_str='\0';
return &tmp_str[0];
}
string (only leading and trailing).
The program itself might not be foolproof but that is not my concern
right now. When I compile this
I get a warning :--
"string_utils.c:96: warning: function returns address of local
variable.
I have declared the fn. as fn. pointer and this fn. returns the
address of a string array. Why does
the compiler give out this warning? Please help.
Thanks,
Srikar
PROGRAM:
--------------
char *xstrip(char *); //declaration.
char *xstrip(char *c)
{
int i=0;
char tmp_str[xstrlen(&c[0])];
while(*c != '\0')
{
if(*c==32) // if space.
{
if((*(c+1)!=32 && *(c-1)!=32))
;
else
{
c++;
continue;
}
}
tmp_str=*c;
i++;
c++;
}
//Adding null char to indicate end of string. Else printf would
not know where str ends.
tmp_str='\0';
return &tmp_str[0];
}