this is part of a homework assignment using structs and I can't seem to understand this one function. The function is string_t *concat (string_t *s1, string_t *s2) and it returns the new string struct. This is what I have so far, and it crashes the compiler whenever it's reached. The program compiles but, "file".exe has stopped working error comes up when executing. Any help would be greatly appreciated. Thanks!
typedef struct string{ //String struct (in .h file)
char *line;
int length;
} string_t;
string_t* concat(string_t *s1, string_t *s2) { //actual function (in .c)
int len1, len2;
len1 = length(s1);
len2 = length(s2);
int i, j, s;
string_t *newStr;
newStr = (string_t*)malloc(sizeof(string_t)*2);
for (i = 0; i<len1; i++) {
*((newStr->line)+i) = *((s1->line)+i);
}
for (j=0; j<len2; j++) {
*((newStr->line)+(i+j)) = *((s2->line)+j);
}
*((newStr->line)+(i+j))='\0';
return newStr;
}
concat(s1, s2); //tests function