File Operations PDF
Document Details
Uploaded by LuxuryAbundance
Algonquin College
Surbhi Bahri
Tags
Summary
This document is a set of C programming notes concerning file operations, including functions like fputc, fgetc, putw, getw, fputs, fgets, fprintf, and fscanf. It uses relevant examples, such as struct record for understanding the use of fwrite().
Full Transcript
FILE OPERATIONS Authored by Professor Surbhi Bahri int fputc(int c, FILE *fptr); int fgetc(FILE *fptr); int putw(int value, FILE *ptr); int getw(FILE *fptr);...
FILE OPERATIONS Authored by Professor Surbhi Bahri int fputc(int c, FILE *fptr); int fgetc(FILE *fptr); int putw(int value, FILE *ptr); int getw(FILE *fptr); int fputs(const char *str, FILE *fptr); char *fgets(char *str, int n, FILE *fptr); fprintf(FILE *fptr, const char *format[, argument,...]); or fprint(stdout, "My age is %d", age); fscanf(FILE *fptr, const char *format[, address,....]); size_t fwrite(const void *ptr, size_t size, size_t n, FILE *fptr); typedef unsigned int size_t; fwrite(arr, sizeof(arr), 1, fp); struct record { char name; int roll; float marks; }student; main() { Surbhi Bahri | ALGONQUIN COLLEGE DO NOT COPY, SHARE OR DISTRIBUTE CONTENT. IT IS STRICTLY FORBIDDEN TO MAKE UNAUTHORIZED WEB POSTINGS OF THE CONTENTS. int n, i; FILE *fp; fp=fopen("stu.dat", "w"); if(fp==NULL) { printf("Error in opening file"); exit(1); } printf("Enter the number of records"); scanf("%d", &n); for(i=0; i