how to read and write a file in c

 #include<stdio.h>

int main()

{

FILE *fptr;

int num = 45;

fptr = fopen("generated.txt", "w");

fprintf(fptr,"The number is %d\n",num);

fprintf(fptr , "thank you baby\n");

fclose(fptr);

  return 0;

}


#include<stdio.h>

 

int main()

{

  FILE *ptr;

    int num;

  ptr = fopen("nilabhrudas.txt","r");

  fscanf(ptr,"%d\n",&num);

  fprintf("The value of the num is %d\n", num);

  return 0;

}


#include<stdio.h>

int main()

{

  FILE *ptr;

  char c;

  ptr = fopen("nayan.txt","r");

  c = fgetc(ptr);

  while(c!=EOF){

  printf("%c",c);

  c = fgetc(ptr);

  }

  return 0;

}

Comments

Popular posts from this blog

create a num table in a new file in c

write a programme to compare time stamp in c

write a struct programme to keep bank details in c