hi people.
i tried looking for a function that chops the newline off of a string but couldnt find one so i went about writing my own function to do it.
here is the code
Code:
/* removes the newline character from a string */
char* chop(char *string)
{
int i, len;
len = strlen(string);
char *newstring;
newstring = (char *)malloc(len-1);
for(i = 0; i < strlen(string)-1; i++)
{
newstring[i] = string[i];
printf("in the string %c\n", string[i]);
}
printf("len og newstring %d\n", strlen(newstring));
printf("string now .......... %s\n", newstring);
return newstring;
}
this doesnt seem to work because it keeps giving me a string which is longer than the len-1 size i require. it just seems to put garbage at the end of it.
Any help is greatly appreciated