keep getting error need help!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: keep getting error need help!

  1. #1
    Join Date
    Mar 2013
    Posts
    2

    keep getting error need help!

    Here is my code so far, the problem is when I debug it I keep getting the same error but everything seems to be correct.
    The error is:
    Unhandled exception at 0x00ED8F34 in ENCDEC.exe: 0xC0000005: Access violation reading location 0x00000008.

    #include <iostream>
    #include <fstream>
    #include <string>
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <ctype.h>

    using namespace std;
    char buffer[100];

    class cSecret{
    public:
    cSecret();
    ~cSecret();
    void choice();
    void encrypt();
    void decrypt();
    void open();
    void save();
    void key();

    private:
    ifstream infile;
    ifstream infile1;
    ofstream outfile;
    ofstream outfile2;
    int key1;
    string input;
    int lengthable;
    int choice1;
    int x,i;
    };

    cSecret::cSecret()
    {
    int key1 = 0;
    int lengthable = 0;
    int choice1 = 0;
    int x = 0;

    }

    cSecret::~cSecret()
    {
    }


    void cSecret::choice()
    {
    printf("Press 1 for ROT13 encryption of 2 for XOR: \n");
    cin >> choice1;

    if(choice1==1)
    {
    printf( "ROT13 encryption\n");

    } else if (choice1==2)
    {
    printf("XOR encryption\n");

    }
    }

    void cSecret::encrypt()
    {
    lengthable = sprintf(buffer, "%s", buffer);
    if (choice1==1){
    for(x=0; x < lengthable;x++){
    if (buffer[x] > 'A' && buffer[x] < 'N' || buffer[x] > 'a' && buffer[x] < 'n') {
    buffer[x] += 13;
    } else if (buffer[x] > 'M' && buffer[x] < 'Z' || buffer[x] > 'm' && buffer[x] < 'z') {
    buffer[x] -= 13;
    }
    }
    } else
    if (choice1==2){
    printf("Enter encryption key: ");
    cin >> key1;
    for(x=0; x < lengthable;x++){
    buffer[x] ^= key1;
    }
    }
    }

    void cSecret::decrypt()
    {
    printf("Press 1 for ROT13 or 2 for XOR decryption\n");
    cin >> choice1;
    lengthable = sprintf(buffer,"%s", buffer);
    if (choice1==1){
    for(x=0; x < lengthable;x++){
    if (buffer[x] > 'A' && buffer[x] < 'N' || buffer[x] > 'a' && buffer[x] < 'n') {
    buffer[x] += 13;
    } else if (buffer[x] > 'M' && buffer[x] < 'Z' || buffer[x] > 'm' && buffer[x] < 'z') {
    buffer[x] -= 13;
    }
    }
    } else
    if (choice1==2){
    for(x=0; x < lengthable;x++){
    buffer[x] ^= key1;
    }
    }
    }

    void main(char* argc[],int argv)
    {
    cSecret robot;
    FILE *pfile;
    pfile = fopen(argc[1],"r");
    fread(buffer, 1, 10000, pfile);
    int i;
    robot.choice();
    robot.encrypt();
    FILE *sfile;
    sfile = fopen(argc[2], "w");
    fputs(buffer, sfile);
    robot.decrypt();
    FILE *sfile2;
    sfile2 = fopen(argc[3], "w");
    fputs(buffer, sfile2);

    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,446

    Re: keep getting error need help!

    Quote Originally Posted by josh223456 View Post
    Here is my code so far, the problem is when I debug it I keep getting the same error but everything seems to be correct.
    The error is:
    Unhandled exception at 0x00ED8F34 in ENCDEC.exe: 0xC0000005: Access violation reading location 0x00000008.
    1) Use code tags when posting code. The code you posted is practically unreadable.

    2)
    Code:
    	FILE *pfile;
    	pfile = fopen(argc[1],"r");
    	fread(buffer, 1, 10000, pfile);
    What happens if that file can't be opened? You should be checking for NULL after you call fopen().

    3)
    Code:
    char buffer[100];
    //...
    fread(buffer, 1, 10000, pfile);
    Do you see a problem here?

    4)
    Code:
    void main(char* argc[],int argv)
    The main() function returns int, not void. In addition, those arguments are not correct and are in the wrong order.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 3rd, 2013 at 05:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center