Search
 
SCRIPT & CODE EXAMPLE
 

C

write in file in c

#include<stdio.h>
int main(){
	FILE *out=fopen("name_of_file.txt","w");
	fputs("Hello File",out);
	fclose(out);
	return 0;
}
Comment

Read Write in File in C language

//////WRITE

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int num;
   FILE *fptr;

   // use appropriate location if you are using MacOS or Linux
   fptr = fopen("C:program.txt","w");

   if(fptr == NULL)
   {
      printf("Error!");   
      exit(1);             
   }

   printf("Enter num: ");
   scanf("%d",&num);

   fprintf(fptr,"%d",num);
   fclose(fptr);

   return 0;
}

//////READ

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int num;
   FILE *fptr;

   if ((fptr = fopen("C:program.txt","r")) == NULL){
       printf("Error! opening file");

       // Program exits if the file pointer returns NULL.
       exit(1);
   }

   fscanf(fptr,"%d", &num);

   printf("Value of n=%d", num);
   fclose(fptr); 
  
   return 0;
}
Comment

write to file in c programming

  [...]
  printf("Enter name: 
");
  if (fgets(name, sizeof name, stdin)) {
    fputs(name,fileptr);
    fclose(fileptr);
    printf("File write was successful
");
  } else {
    printf("Read error.
");
  }
Comment

PREVIOUS NEXT
Code Example
C :: c declare float 
C :: bucket sort 
C :: print binary c 
C :: array of string in c 
C :: merge sort in c 
C :: matrix of string in c 
C :: how to find the elements in array c coding 
C :: c local variable 
C :: unox reclame harmonica tabs 
Dart :: screen size flutter 
Dart :: How to attach a FloatingActionButton to the AppBar 
Dart :: flutetr stepper color 
Dart :: const text style flutter 
Dart :: flutter text hint 
Dart :: dart convert string to datetime 
Dart :: how to print in the same line in dart 
Dart :: flutter get device width 
Dart :: setting backgroundColor for snack bar does not change background color 
Dart :: hive regiter adapter enum 
Dart :: flutter datetime.now only time 
Dart :: type convertion string to double 
Dart :: dart try-catch 
Dart :: open another page with routeflutter 
Dart :: dart list remove range 
Dart :: flutter safearea 
Dart :: elevatebutton in flutter 
Dart :: dart uri 
Dart :: raisedbutton full width flutter 
Dart :: flutter random int 
Dart :: Flutter get each letter from string 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =