I have a string that has a bunch of white space on the end of it and was wondering if there is a simple way to eliminate the trailing white space with a standard C function. I know there is one called "String.trim" but I can't use anything that isn't in the standard C library.
here is what i have, if you have a more efficient way to read the data to avoid reading the whitespace, that is more than welcome too.
fgets(char_buffer,40,file); strcpy(my_show_array[i].show_name, char_buffer); printf("show name = %s\n", my_show_array[i].show_name);
Of course "show_name" is not always the same so i have to assign enough space to hold at least 40 characters if needed. however if it is not needed, I want to trim it down.
If I do a print statement,
printf("%s is my string", my_show_array[i].show_name);
Assuming my_show_array.show_name = "my string" It prints this out,
"my string is my string" /*notice I don't want to eliminate ALL white space b/c my_show_array[i].show_name has a space in between the two words, "my" and "string"*/
I think it's either a lot of white space or perhaps an end of line marker...
I ran a strlen command and it returned something small like 8, so it must be an end of line marker b/c it always prints out on the next line in the command window when I run the program. I still don't know how to get rid of this though.