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;
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/