Hey guys,
I have a simple function that reads info from a file and stores in into arrays. An example of the file is shown below:
1 2 Text
3 4 More Text
5 6 Even More Text
1000
So basically, the program scans in the first number, second number and text until it reaches the sentinel 1000 and it stops.
Here's the code
Code:
i=0;
fscanf(workout, "%d", &set[i]);
while (set[i] != 1000) {
fscanf(workout, "%d ", &increment[i]);
fgets(drill_name[i], SIZE, workout);
drill_name[i][strlen(drill_name[i])-1]='\0';
i++;
fscanf(workout, "%d", &set[i]);
}
When I run this program it crashes with error:
Program received signal: “EXC_BAD_ACCESS”.
However, I've found out that when I take out the line of code:
Code:
drill_name[i][strlen(drill_name[i])-1]='\0';
The program works fine. But I need this code there to remove the newline character after each text. I have some similar functions in my program that have the same line of code and work fine, so what's going wrong here?
Thanks