Thread: Compiling Problems...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    27

    Compiling Problems...

    I tried making a simple file encrypter....

    what it does it open a file, get 1 char by char. take that char and add the "key" to it..

    So char "A" which is 65 added to (lets say key is 1) 1 is 66 which is "B"

    the dycrpted would decrypt this but i cant compile it. And please check for errors or any suggestions, and if this program will work

    These are teh compile errors under cl.exe
    Code:
    xcrypt.cpp
    xcrypt.cpp(37) : error C2362: initialization of 'make' is skipped by 'goto end'
            xcrypt.cpp(27) : see declaration of 'make'
    xcrypt.cpp(37) : error C2362: initialization of 'make' is skipped by 'goto end'
            xcrypt.cpp(27) : see declaration of 'make'
    xcrypt.cpp(37) : error C2362: initialization of 'read' is skipped by 'goto end'
            xcrypt.cpp(19) : see declaration of 'read'
    the code:

    Code:
    #include<iostream.h>
    #include<fstream.h>
    
    int main()
    {
    	char Filename[50], chr;
    	int Key;
    	
    	cout<<"Enter Filename To Encrypt";
    	cin>>Filename;
    	cout<<"Enter Key # (1-10)";
    	cin>>Key;
    
    	if(Key>10){ // Checks if key is no greater then 10
    		cout<<"Invalid Key";
    		goto end;
    	}
    	
    	ifstream read;
    	read.open(Filename,ios::in);
    
    	if(!read){ // Checks if file exists
    			cout<<"Unable To Open File";
    			goto end;
    	}
    	ofstream make; // Creats file "Encrypted.tmp"
    	make.open("Encrypted.tmp",ios::out);
    
    	while(read)
    	{
    		read.get(chr); // Gets chr
    		chr = chr + Key; // Takes the char and adds to it 'Key'
    		make<<chr; // Writes Encrypted chr
    	}
    
    	end:
    	return 0;
    
    }

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    It seems to be choking cuz you are declaring an ifstream and an ofstream after a possible jump....

    If you must use goto for this, put the declarations at the top of the code block

    Code:
    #include<iostream.h>
    #include<fstream.h>
    
    int main()
    {
    	char Filename[50], chr;
    	int Key;
    	ifstream read;
    	ofstream make; // Creats file "Encrypted.tmp"
    	
    	cout<<"Enter Filename To Encrypt";
    	cin>>Filename;
    	cout<<"Enter Key # (1-10)";
    	cin>>Key;
    
    	if(Key>10){ // Checks if key is no greater then 10
    		cout<<"Invalid Key";
    		goto end;
    	}
    	
    	
    	read.open(Filename,ios::in);
    
    	if(!read){ // Checks if file exists
    			cout<<"Unable To Open File";
    			goto end;
    	}
    	
    	make.open("Encrypted.tmp",ios::out);
    
    	while(read)
    	{
    		read.get(chr); // Gets chr
    		chr = chr + Key; // Takes the char and adds to it 'Key'
    		make<<chr; // Writes Encrypted chr
    	}
    
    	end:
    	return 0;
    
    }

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    thank you that worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  2. problems with including headers
    By l2u in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 08:06 AM
  3. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 01:09 AM
  4. Linking problems, class problems
    By Kheila in forum C++ Programming
    Replies: 12
    Last Post: 11-22-2005, 01:47 AM
  5. compiling problems LNK2019 error
    By sugie in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2005, 05:25 PM