Hello again,
I´ve made a small substring() function that shoudl give back the a
susbtring from a string, given its start and end positions.
Is there any chance of the code below give an output containing data
from another memory area that is completely unrelated to the input
string? This is happening and the start/end parameters are acceptable
(within bounds) for the input string...any idea?
char *substring(char *string, int start, int end){
printf("Input %s:", string);
char *result = (char *)malloc((end - start + 1)*sizeof(char));
if(result == NULL){
return(NULL);
}
string = string + start;
while(start < end){
*result = *string;
result++;
string++;
start++;
}
printf("Output %s:", result);
return(result);
}