Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define MAXSIZE 100
- int main(void)
- {
- FILE *message;
- FILE *encryptMessage;
- FILE *key;
- message = fopen("message.txt", "r");
- encryptMessage = fopen("encryptMessage.txt", "w");
- key = fopen("key.txt", "w");
- if ((message == NULL) || (encryptMessage == NULL) || (key == NULL))
- {
- printf("Error reading file!!!\n");
- return 1;
- }
- int userKey;
- char sentence[MAXSIZE];
- char q[MAXSIZE];
- int i = 0;
- // printf("Input the text that you want to encrypt:\n> ");
- // fgets(sentence, 99, message);
- // printf("\nThe string that you wrote is:\n%s\n\n", sentence);
- printf("Input the key:\n");
- scanf("%d", &userKey);
- fprintf(key, "%d", userKey);
- //printf("\nThe key that you selected is: %d\n\n", userKey);
- while (fgets(sentence, MAXSIZE - 1, message)) {
- for(i = 0; sentence[i] != '\0'; ++i)
- {
- if( ( isupper(sentence[i]) ) || ( islower(sentence[i]) ) )
- {
- q[i] = sentence[i] + (char)userKey;
- }
- else
- {
- q[i] = (sentence[i]);
- }
- }
- q[i] = '\0';
- fprintf(encryptMessage, "%s", q);
- }
- fclose(encryptMessage);
- fclose(key);
- fclose(message);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment