C/C++ Caesar Cipher on a .txt file?

Discussion in 'C++' started by BillyBob, Dec 15, 2007.

Thread Status:
Not open for further replies.
  1. BillyBob

    BillyBob New Member

    Joined:
    Dec 14, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi, How would I go about using the Caesar Cipher technique on a .txt file? E.g. shifting each letter by 3?

    Here is my code?

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define CNTRLZ 0x1A
    
    char sourceFileName[] = "H:\\text.txt";
    char commStreamName[] = "COM1";
    FILE *commStream;
    FILE *SouceFile;
    char charToSend;
    char ReadAccess[] = "r";
    char WriteAccess[] = "w";
    char errorMsg[] = "fail to open data file\n";
    char fileopenflag[] = "r";
    char EndOfFile[] = "EOF";
    
    int main(void) {
    FILE *fp;
    FILE *dp;
    int c;
    
    if ((dp = fopen("COM1", "r")) == NULL) {
    printf("fail to open COM port\n"); return 1;
    }
    
    
    if ((fp = fopen( sourceFileName, "w")) == NULL) {
    printf("fail to open data file\n"); return 1;
    }
    
    
    while ((c = fgetc(fp )) != EOF) {
    fputc( c, dp);
    putch(c);
    
    }
    
    fputc('*', dp);
    fclose(dp);
    fclose(fp);
    }
    Any ideas where to start?
     
    Last edited by a moderator: Dec 16, 2007
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
  3. BillyBob

    BillyBob New Member

    Joined:
    Dec 14, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    You weren't no help as usual.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice