Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<stdbool.h>
- #include<string.h>
- #include<time.h>
- const size_t LIM = 128;
- char* newstr(size_t s){
- return malloc((s + 1) * sizeof(char));
- }
- char decrypt(char c){
- if (c == 'a' || c == 'A'){
- return c + 'z' - 'a';
- } else if (isalpha(c)){
- return c - 1;
- } else {
- return c;
- }
- }
- int main(int argc, char* argv[]){
- if (argc > 2){
- puts("Error. Invalid console argument count.");
- return 0;
- }
- char *filename;
- if (argc == 1){
- printf("Enter filename: ");
- filename = newstr(LIM);
- scanf("%[a-zA-Z0-9_]", filename);
- } else {
- filename = argv[1];
- }
- const char
- *filename_in =
- newstr(strlen(filename) + strlen(".IN")),
- *filename_out =
- newstr(strlen(filename) + strlen(".OUT"));
- strcpy(filename_in, filename);
- strcpy(filename_out, filename);
- strcat(filename_in, ".IN");
- strcat(filename_out, ".OUT");
- FILE *in = fopen(filename_in, "r"),
- *out = fopen(filename_out, "w");
- int cout;
- printf("Print result to console?\n"
- "1. Yes.\n"
- "2. No.\n"
- "Your choice: ");
- scanf("%d", &cout);
- if (cout != 1 && cout != 2){
- puts("Error.");
- fclose(in);
- fclose(out);
- return 0;
- }
- for (int t = fgetc(in); t != EOF; t = fgetc(in)){
- fputc(decrypt(t), out);
- if (cout == 1){
- putchar(decrypt(t));
- }
- }
- fclose(in);
- fclose(out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement