read file in C
snippet in c

read files in c

user6150

#include<stdio.h>
int main(){
	FILE *in=fopen("name_of_file.txt","r");
	char c;
	while((c=fgetc(in))!=EOF)
		putchar(c);
	fclose(in);
	return 0;
}

c write to file

user6072

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

int main() {
    char sentence[1000];

    // creating file pointer to work with files
    FILE *fptr;

    // opening file in writing mode
    fptr = fopen("program.txt", "w");

    // exiting program 
    if (fptr == NULL) {
        printf("Error!");
        exit(1);
    }
    printf("Enter a sentence:\n");
    fgets(sentence, sizeof(sentence), stdin);
    fprintf(fptr, "%s", sentence);
    fclose(fptr);
    return 0;
}

read file in C

user5009

#include <stdio.h>

int main() {
  	char contents[3000];
	FILE *fp = fopen("filename.txt", "r");
	fscanf(fp, "%s", contents);
  	printf(contents);
}

file in C

user9842

//to open a file
FILE=*fp;
fp=fopen("one.txt", "w");
//to close file 
fclose(fp);