Not Sure What I'm missing.

I have been given some code which reads some values from a .txt document. It supposedly was tested on a PC compiler and runs perfectly. However, when I try to run it through Xcode's C++ I receive a:
'Thread 1: EXC_BAD_ACCESS code=1, address =0x68' message.

Here is the code, if you guys could please point out what I'm missing...that would be brilliant. I am new to C++ so hopefully it isn't too stupid of a mistake.
Thank You.

/* fscan example */
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

/* char str [80];
int i;

printf ("Enter your family name: ");
scanf ("%79s",str); <<<<This is where the error is.
printf ("Enter your age: ");
scanf ("%d",&i);
printf ("Mr. %s , %d years old.\n",str,i); */
int main()
{

float overpotential[1000], current_density[1000];
int i=0, ipairs=0;
char top_line[80];
FILE *pFile;

pFile = fopen("Al.txt","r");
fscanf(pFile, "%79s", top_line);
fscanf(pFile, "%i", &ipairs);
cout<<top_line<<"\n";
cout<<ipairs<<"\n";
while (i<ipairs)
{
fscanf(pFile, "%f %f", &overpotential[i], &current_density[i]);
cout<<overpotential[i]<<" " <<current_density[i] <<"\n";
// cout<<i<<"\n";
i++;

}
//now find OCP by searching current_density for near zero value, interpolating and calculating OCP


//cout<<i;



fclose(pFile);


}


Thank You so much for taking time to look at my question. I'm appreciative of any and all help.
The only thing that jumps out at me is the following line:
 
    pFile = fopen("Al.txt","r");

You don't check if the open succeeded or not. If the open fails, you attempt the subsequent fscan anyway. This will likely cause a run time error.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/

Does the file exist, or is the path to the file correct.

You should also test if the file is opened successfully, your code assumes that it was opened regardless if it was or not.

@AbstractionAnon, sorry, not refreshing page creeping up on me again :)
Topic archived. No new replies allowed.