fgets and fputs
Read a line safely into a buffer; write a string.
Beginner
char line[128];
while (fgets(line, sizeof line, f)) { /* line includes '\n' if it fit */ }
Remove the newline with line[strcspn(line, "\n")] = '\0';. Never use the removed gets.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.