Write a program to change the case of each letter in a file.
#include<stdio.h> void Change_Case_file(FILE*); int main() { char fileName[50]; FILE *fileptr; printf("Enter file name : "); scanf("%[^\n]",fileName); fileptr = fopen(fileName,"r+"); if(fileptr == NULL) { printf("%s File is not present in this directory\n",fileName); return 0; } Change_Case_file(fileptr); return 0; } void Change_Case_file(FILE *p) { char ch; while((ch = fgetc(p)) != EOF) { if(((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) { ch = ch ^ 32; fseek(p,-1,SEEK_CUR); fputc(ch,p); } } fclose(p); printf("Conversion Done....\n"); }
Note: File named data is present in the current working directory.
cat data Lot To Learn BlackBerry Iphone Incredible India
Output
Enter file name : data Conversion Done....
cat data lOT tO lEARN bLACKbERRY iPHONE iNCREDIBLE iNDIA
Enter file name : data Conversion Done....
cat data Lot To Learn BlackBerry Iphone Incredible India