views:

415

answers:

0

What is wrong with my code? (I'm trying to at least get copy a file with this code in XCode (OS X 10.6 Snow Leopard.) I keep on getting a SIGABRT with an malloc_error when running:

Lesson 4(796) malloc: *** error for object 0x10000a8a0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Here's the code (main.cpp):

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
void encrypt(char plainFile[], char cipherFile[], int key);
void decrypt(char cipherFile2[], char plainFile2[], int key);

void encrypt(char plainFile[], char cipherFile[], int key){
 ifstream fin;
 fin.open(plainFile);

 if (fin.fail()){ // check if "input.txt" is open
  cout << " ";
  exit(1);
 }

 ofstream fout(cipherFile);
 string outputStuff;
 fin >> outputStuff;
 fout << outputStuff;
 fin.close();
 fout.close();
}

void decrypt(char cipherFile2[], char plainFile2[], int key){
 }


int main (int argc, char * const argv[]) {

    encrypt("L04_plain1.txt", "cipher1.txt", 3);
 //decrypt("L04_cipher2.txt", "plain2.txt", 3);

 return 0;
}

I have the files needed ("L04_plain1.txt" and "L04_cipher2.txt" in both the Build folder and in the outer folder - the one with the project file and main.cpp).

Please help!!!!!!