#include<stdio.h> main() { FILE *fp; fp=fopen("c://temp/ccit.txt","r"); if(fp==NULL) printf("File dos'nt exists..."); else { int ch; do { ch=fgetc(fp); putchar(ch); } while(ch!=EOF); fclose(fp); } }
Welcome to CCIT
#include<stdio.h> main() { FILE *fptr; char name[20]; char add[50]; fptr = fopen("c://temp/info.txt", "w"); if (fptr == NULL) { printf("File does not exists \n"); } printf("Enter the Name \n"); scanf("%s", name); fprintf(fptr, "Name = %s\n", name); printf("Enter the Address \n"); scanf("%s", add); fprintf(fptr, "Address = %s\n", add); }
Enter the Name Amit Enter the Address Amravati ------------------------------ Name = Amit Address = Amravati
#include<stdio.h> main() { FILE *fptr1, *fptr2; char filename[100], c; printf("Enter the filename to open for reading \n"); scanf("%s", filename); fptr1 = fopen(filename, "r"); if (fptr1 == NULL) { printf("Cannot open file %s \n", filename); } printf("Enter the filename to open for writing \n"); scanf("%s", filename); fptr2 = fopen(filename, "w"); if (fptr2 == NULL) { printf("Cannot open file %s \n", filename); } c = fgetc(fptr1); while (c != EOF) { fputc(c, fptr2); c = fgetc(fptr1); } printf("\nContents copied to %s", filename); fclose(fptr1); fclose(fptr2); return 0; }
Enter the filename to open for reading c://temp/info.txt Enter the filename to open for writing c://temp/backup.txt Contents copied to c://temp/backup.txt --------------------------------