Using fgets() and fputs() to read and output string - C File

C examples for File:File Write

Description

Using fgets() and fputs() to read and output string

Demo Code

#include <stdio.h>

#define STLEN 10/*from  w  w w .j a  v a 2s .c  o  m*/

int main(void)
{
    char words[STLEN];
    
    puts("Enter strings (empty line to quit):");
    while (fgets(words, STLEN, stdin) != NULL && words[0] != '\n')
        fputs(words, stdout);
    puts("Done.");
    
    return 0;
}

Result


Related Tutorials