Virajsinh

FileHandling_2

Nov 16th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. //Encrypt Data Store in Text File
  2.  
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8.     FILE *fp1, *fp2;
  9.     char str[500];
  10.     int i, ch;
  11.     clrscr();
  12.  
  13.     //First Create a File. Path ->  C:/TurboC4/TC/Bin/
  14.     fp1=fopen("LIS.txt","r");
  15.     if(fp1==NULL)
  16.     {
  17.         printf("\n Opened");
  18.         exit(1);
  19.     }
  20.     ch=fgetc(fp1);
  21.  
  22.     for(i=0;(i<500)&&(feof(fp1)==0);i++)
  23.     {
  24.         str[i]=(char)ch;
  25.         ch=fgetc(fp1);
  26.     }
  27.  
  28.     str[i]='\0';
  29.     printf("\n Actual Data : %s ", str);
  30.     fclose(fp1);
  31.  
  32.     //Encrypted Data File Created
  33.     fp2=fopen("Hello.txt","w");
  34.  
  35.     if(fp2==NULL)
  36.     {
  37.         printf("\n Opened");
  38.         exit(1);
  39.     }
  40.  
  41.     for(i=0;i<str[i];i++)
  42.     {
  43.         str[i]=str[i]-2;
  44.         fputc(str[i],fp1);
  45.     }
  46.     printf("\n Encrypt Data : %s", str);
  47.     fclose(fp2);
  48.     getch();
  49. }
Add Comment
Please, Sign In to add comment