?
=?ISO-8859-1?Q?Micha=EBl_Boland?=
I have a fonction to trim a string :
char *trimstr(char *pbuf1)
{
char *pbuf2 , *pbuf3;
pbuf2 = pbuf1 ;
pbuf3 = pbuf1 ;
while(*pbuf1 != '\0') { if(*pbuf1 != ' ') { pbuf2 = pbuf1; pbuf2++; }
pbuf1++; }
while(*pbuf2 != '\0') { *pbuf2 = '\0'; pbuf2++; }
return(pbuf3) ;
}
main(int argc, char *argv[], char *env[])
{
trimstr(" tata ");
return 0;
}
It's ok with Unix Digital.
The result with Linux is Segmentation fault.
I think the problem is " tata " is a const *char and C Linux don't
allow to change a constant.
Is it possible in the function trimstr to know if the argument is a
*char or a const *char?
Or anything else solution?
Regards.
Michaël
char *trimstr(char *pbuf1)
{
char *pbuf2 , *pbuf3;
pbuf2 = pbuf1 ;
pbuf3 = pbuf1 ;
while(*pbuf1 != '\0') { if(*pbuf1 != ' ') { pbuf2 = pbuf1; pbuf2++; }
pbuf1++; }
while(*pbuf2 != '\0') { *pbuf2 = '\0'; pbuf2++; }
return(pbuf3) ;
}
main(int argc, char *argv[], char *env[])
{
trimstr(" tata ");
return 0;
}
It's ok with Unix Digital.
The result with Linux is Segmentation fault.
I think the problem is " tata " is a const *char and C Linux don't
allow to change a constant.
Is it possible in the function trimstr to know if the argument is a
*char or a const *char?
Or anything else solution?
Regards.
Michaël