Program to use fscanf() and fprintf() functions


#include <stdio.h>

main()
{
  FILE *fp;
  char s[80];
  int t;

  if((fp=fopen("test", "w")) == NULL)
  {
    printf("Cannot open file.\n");
    exit(1);
  }

  printf("Enter a string and a number: ");
  fscanf(stdin, "%s", s); /* read from keyboard */

  fprintf(fp, "%s", s); /* write to file */
  fclose(fp); 

  if((fp=fopen("test","r")) == NULL) 
  {
    printf("Cannot open file.\n");exit(1);
  }

  fscanf(fp, "%s", s); /* read from file */
  fprintf(stdout, "%s", s); /* print on screen */

  getch();

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples