Mark H
0
Q:

fgets in c

<open file>
while(fgets(<char array>, <size of array>, <file pointer>) != null)
4
// C program to illustrate 
// fgets() 
#include <stdio.h> 
#define MAX 15 
int main() 
{ 
    char buf[MAX]; 
    fgets(buf, MAX, stdin); 
    printf("string is: %s\n", buf); 
  
    return 0; 
} 
1
// C program to illustate fputc() function 
#include<stdio.h> 
int main() 
{ 
    int i = 0; 
    FILE *fp = fopen("output.txt","w"); 
  
    // Return if could not open file 
    if (fp == NULL) 
      return 0; 
  
    char string[] = "good bye", received_string[20]; 
  
    for (i = 0; string[i]!='\0'; i++) 
  
        // Input string into the file 
        // single character at a time 
        fputc(string[i], fp); 
  
    fclose(fp); 
    fp = fopen("output.txt","r"); 
  
    // Reading the string from file 
    fgets(received_string,20,fp); 
  
    printf("%s", received_string); 
  
    fclose(fp); 
    return 0; 
} 
0
char str[20]; //declare string of 20
fgets(str, 20, stdin); // read from stdin
puts(str); // print read content out to stdout
  
0

New to Communities?

Join the community