Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

runtime error caused by fscanf in VSP 6.0?

Status
Not open for further replies.

robk3

Programmer
Jul 3, 2006
11
0
0
US
I am tryting to write a program in Visual Studio Pro 6.0, in C, and when I run it I get a urntime error: Debug Error!

when I originally had a loop after the scanf loop to print out the values that were read in, everything looked fine. I removed the printf and get the error, put the printf back in and the error goes away. Can anyone tell me what is wrong with this code and suggest how it might be fixed?

/ Multiequater2000.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>



void CreateFCIPFiles();


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

return 0;
}

void CreateFCIPFiles()
{

struct itemInfo
{
int id, model, linking;
double a, b, c, thresh1, thresh2, thresh3, thresh4;
};

char line[80];
struct itemInfo items[78];
int conditionCounter, yearCounter, repCounter, itemCounter;
FILE *fpItemInfo;


conditionCounter = 0;
yearCounter = 1;
repCounter = 1;


sprintf(line, "equating_project\\condition%2.2i\\year%2.2i\\pramr ef%2.2i.txt", conditionCounter, yearCounter, repCounter);

if (( fpItemInfo = fopen( line, "r")) == NULL)
{
printf("Input specification file %s cannot be opened.\n\n", line);
exit (1);
}

for(itemCounter = 0; itemCounter<78; itemCounter++)
{
fscanf(fpItemInfo, "%i %i %i %lf %lf %lf %lf %lf %lf %lf", &items[itemCounter].id, &items[itemCounter].model, &items[itemCounter].linking, &items[itemCounter].a, &items[itemCounter].b, &items[itemCounter].c, &items[itemCounter].thresh1, &items[itemCounter].thresh2, &items[itemCounter].thresh3, &items[itemCounter].thresh4);
}

fclose(fpItemInfo);
}


this is a sample of the first line form the input file being read:

226316 1 0 1.02681 -0.93143 0.13604 0.00000 0.00000 0.00000 0.00000
 
Do you have the latest VC++ 6.0 service pack?
Does it happen in Release mode or just Debug mode?
What's the exact error message you get?
 
I have the latest service pack.

It happens in release mode, maybe in debug mode too, I'll try it if you wnat. The exact error:

Runtime Error
FILENAME

Debug Error!

and this is in release mode.

rob
 
I can't see anything wrong with the code.

Try putting a breakpoint before the fscanf() loop, then step through to see where the error happens.

It's strange that it would say "Debug Error" in Release mode... Check your project settings to see if you're linking only debug libraries in Debug mode and only release libraries in Release mode. Also make sure you're not mixing single-threaded & multi-threaded libraries together.
 
Print itemCounter and the data that you are reading. How far does it get before you get the error?
 
I did those things. The error happens at the scnf line.

I appreciate your help, but I have given up. I tried running the code in Xcode in OS X and it ran fine. I decided it was something about VSP or the project file not the code that was the problem. I rebuilt the project from scratch, and still had the same problem. I downloaded the Pelles compiler, and the problem went away. I like the pelles editor better as well. I am moving on, and getting this thing finished.

I am a mac programmer forced to work in windows for part of my dissertation project, as I must call a windows console app from within my program. Things are progressing smoothly using Pelles, and I am happy to leave this as a mystery. If you are able to copy and paste the code and reproduce the eroor, I am happy to read about it, but don't do it on my acocunt.

rob
 
the error happens when itemCounter == 0.

rob
 
I tried compiling and running your code in VC++ 6.0 and got the same error. I then compiled and ran in VC++ 2005 Express and it ran fine. I think you're right; it looks like a compiler bug.

BTW, you can download and use Visual C++ 2005 Express Edition for free from Microsoft's website.
 
I actually have access to all of the MS developer tools for free through the MSDN-AA and my university. Despite this, I am going with Pelles for now, as I really like their editor. Thanks for checking this out in the VC++Express though.


I have VC++ 2005 just in case though.

rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top