kelvin
0
Q:

fputc and fgetc in c

// 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

New to Communities?

Join the community