I get the words from my document extracted and all are printed on screen, but after each word printed there is a blank line. How can I avoid reading or adding this new line to the string?
int main(void) {
FILE *f;
f = ("words", "r");
char string[100];
while (fgets(string, 100, f)) {
printf("%s", string);
}
}
This code was not copy pasted, so I could have forgotten tiny pieces but should work. In words.txt I have one word on each line. My program prints them all to screen, but adds a new line after each word. I do not want it to add a new line, or a space. So if the txt had Hello
on one line and Bye
on the next line, I want it to print HelloBye
. The objective of the final program will not be to print the string, it will be to use the string for something else, so I do need a string that only has the text without spaces at the end or new lines.