sorry I think I blamed the wrong function...here is the code
Code:
//this function works great it adds the second string after the
//null character in base propperly
int build_stream(char * base , char * add)
{
int i;
int len = (strlen(base) + strlen(add)) + 1;
for (i = strlen(base) + 1; i < len ; i++)
{
base[i] = *add++;
}
base[len] = '\0';
return len;
}
// here is where the problem is, this is a function I was making
//to get back the added string after the null into a variable dest.
void getit(char * dest, char * text)
{
int i, j;
int limit = 3;
for (i = limit; *text != '\0'; i++)
{
dest[i-limit] = text[i];
text++;
}
dest[i - limit] = '\0';
}
int main()
{
char myvar[256] = "OK";
char *t = "HELLO";
int j, i;
char user[15] = {}; // this variable will be used to take 'HELLO' back
j = build_stream(myvar, t); // after this call myvar will be holding OKnullHELLOnull
getit(user, myvar); //this call doesnt work properly
printf("myvar: %s\n", myvar); // outputs HELLO since printf works till the first null
printf("user : %s\n", user); // outputs HL for some reason and no HELLO
}