my main:
Code:
int main (void)
{
char g[10]={'F','I','N','E'};
strcat_s539(g, 10, "CHINA");
printf("%s\n", g);
system("pause");
}
my string concatenating function:
Code:
int strcat_s539 (char *dest, unsigned size, const char *source)
{
int i; //variable counter
int j=0; //counter for concatenating w/o nesting
char *temp; //variable to hold a temporary array to copy from source to dest.
temp = malloc(size*sizeof(source)); //allocate array for temporary
if (dest=='\0' || source=='\0' || (strlen539(dest)+strlen539(source))>(size-1)) //test for NULL and size big enough
return (1);
else
{
for (i=0; i<=strlen539(source); ++i)
{
temp[i] = source[i];
}
for (i=(strlen539(dest)); i<=(strlen539(dest)+strlen539(source)); ++i, ++j)
{
dest[i] = temp[j];
}
return (0);
}
free(temp);
}
Perhaps someone can spot my problem?
strlen539 is just a handwritten function that does the same thing as strlen if anyone is wondering b.t.w. and the function actually returns the correct concatenated string: FINECHINA... its just that it brain damages the computer anyway so something is wrong somewhere.