As a newbye, I've justed started writing some code.
Instead of writing 2 different functions for COPY and CONCATENATE string, I'm trying one that will do both:
a) if destination is empty then it will be a simple copy from original string to destination,
b) if destination is not empty, then a concatenation applies.
So, my code is as follows:
#include <stdio.h>
// a CONCATENATE function is similar to a COPY function, with the only
// difference that the copy to destination starts on first empty index
Now, if i run this code, it returns some strange characters.Code:char *f_strcpy(char *v_string) { int length = 0; // determines what is actual length of destination string int i; char dest[100]; // check for length, ignoring termination character for(i=0; dest[i]!='\0'; i++) ; length = i; // // starts concatenation (or simple copy if destination is empty) { for(i=0; v_string[i]!='\0'; i++) dest[length+i]=v_string[i]; // leaves cycle as soon as ='\0' } dest[length+i] = '\0'; // assigns terminator after leaving cycle - otherwise return dest; }
Any ideas?
cheers,
Arr