#include<stdio.h>
#include<stdlib.h>
void saveem()
{
system("cls");
char buffer[80];
FILE *fp, *fp2;
int c;
fp=fopen("C:\Users\Moudi\Desktop\hahaaoida.txt", "a");
fp2=fopen("C:\Users\Moudi\Desktop\hahaaoida2.txt", "a");
fgets(buffer, 80, stdin);
fprintf(fp, "%s", buffer);
system("cls");
fclose(fp);
while ((c=fgetc(fp))!=EOF)
{
fputc(c+4, fp2);
}
printf("Done!\n");
fclose(fp);
fclose(fp2);
}
void deleteem()
{
remove("C:/test.txt");
}
void showem()
{
int a;
char character;
FILE *file,*file2;
file=fopen("C:/test.txt", "rb");
file2=fopen("C:/test2.txt", "wb");
while ((a=fgetc(file))!=EOF)
{
fputc(a-4, file2);
}
fclose(file);
while ((character=fgetc(file2)) != EOF) {
putchar(character);
}
fclose(file2);
remove("C:/test2.txt");
}
int main()
{
char buffer2[20];
int input;
printf("1.Write something in test.txt");
printf("\n2.Delete test.txt\n");
printf("3.Show the content of test.txt\n");
scanf("%d", &input );
switch (input) {
case 1:
saveem();
break;
case 2:
deleteem();
break;
case 3:
showem();
break;
default:
printf(" Bad input, Quitting!\n");
break;
}
getchar();
return 0;
}
So what's happening here if i input "1" it will only show "Done" without asking for the buffer and it won't write it to the file specified.


Sign In
Create Account


Back to top









