R
Rick
Hi,
This is probably piece of cake for you C gurus but it is giving me a
headache. I'm still not really used with pointers and chars so many things
are going wrong. Practicing makes wonders but the problem is that I don't
have much time to practice. Ok, here's the question, how to reset a char
array?
I got this code :
char test[8] = "";
printf( subStr( "result = %s \n" , "blablabla" , 3,5, test ) );
printf( subStr( "result = %s \n" , "another string" , 3,5, test ) );
subStr is a selfmade function which get's a few chars out of the input
parameter and puts it in the output parameter (test in this case). The first
time I use it it works ok, but of course, the second time the test char
array will grow further instead of being replaces. So while the result
should be :
"bla"
"the"
I get
"bla"
"thebla"
It's because of subStr uses strcat and the second time I use it the test
array is still filled with some old stuff. How to get rid of that? I tried
free( test );
between those 2 but that didn't work.
Greetings,
Rick
This is probably piece of cake for you C gurus but it is giving me a
headache. I'm still not really used with pointers and chars so many things
are going wrong. Practicing makes wonders but the problem is that I don't
have much time to practice. Ok, here's the question, how to reset a char
array?
I got this code :
char test[8] = "";
printf( subStr( "result = %s \n" , "blablabla" , 3,5, test ) );
printf( subStr( "result = %s \n" , "another string" , 3,5, test ) );
subStr is a selfmade function which get's a few chars out of the input
parameter and puts it in the output parameter (test in this case). The first
time I use it it works ok, but of course, the second time the test char
array will grow further instead of being replaces. So while the result
should be :
"bla"
"the"
I get
"bla"
"thebla"
It's because of subStr uses strcat and the second time I use it the test
array is still filled with some old stuff. How to get rid of that? I tried
free( test );
between those 2 but that didn't work.
Greetings,
Rick