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

C examples for File:File Write

Description

Use fgets() and fputs() functions to read and output string

Demo Code

#include <stdio.h>

#define STLEN 14/*from ww w . j  ava  2  s  .co  m*/

int main(void){
    char words[STLEN];
    
    puts("Enter a string, please.");
    fgets(words, STLEN, stdin);
    printf("Your string twice (puts(), then fputs()):\n");
    puts(words);
    fputs(words, stdout);
    puts("Enter another string, please.");
    fgets(words, STLEN, stdin);
    printf("Your string twice (puts(), then fputs()):\n");
    puts(words);
    fputs(words, stdout);
    puts("Done.");
    
    return 0;
}

Result


Related Tutorials