Annoying Problem

Started by
1 comment, last by DMSFrever 21 years, 2 months ago
Forgive me if this is something easy to fix cause I am not very fluent yet in programming. Also some of the stuff may be disorginzed slightly (variable names and what not) Allright, In my program, I have a function to check weither to use DirectX or OpenGL. This decision is stored in a file, that line being "apitype: 0 or 1", 0 for DirectX, 1 for OpenGL(Although OpenGL is not yet implimented, it will be after this problem). So I have a while loop to go though the file and search for the "apitype:" lettering. Once it finds it, store it. Then check what the number is and go on initalizing the requested api. So heres part of that function: // If we hit the API tag if( !strcmp( strWord, API ) ) { // Scan the number after the tag fscanf( pFilepointer, "%d", &g_pStartdefines->APItype ); // If the tag reads 0, then use DirectX if( &g_pStartdefines->APItype == 0 ) { // Initiate DirectX InitD3D( hWnd ); return S_OK; } // If the tag reads 1, then use OpenGL else if( &g_pStartdefines->APItype == 1 ) { // Initiate OpenGL (Implimented later) InitD3D( hWnd ); return S_OK; } Now of course the variable "APItype" is stored in a structure: struct tStartdefines { // Used to hold our api request int APItype; }; Now when it comes to compiling, I recive two errors: 1) error C2446: ''=='' : no conversion from ''const int'' to ''int *'' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast 2)error C2040: ''=='' : ''int *'' differs in levels of indirection from ''const int'' Now I am totaly confused on why this wont work, probebly my lack of fluency with C++ but Im learning more and more with each problem Any help will greatly be appriciated. Thanks a lot. I hope I didn''t leave anything out, if somethings confusing, tell me and I will try and clear it up.
Advertisement
Your fscanf function call is correctly implemented. You need a pointer to an int to read in. However, your statements ''if (&g_pStartdefines->APItype == 0)'' and ''else if(&g_pStartdefines->APItype == 1)'', are ill-formed. For in each case you take the pointer of the interger that you want rather than the integer. You should rather set the expression in these two cases to:

g_pStartdefines->APItype == 0

One other thing, fscanf is a dangerous function to use in general. It doesn''t have static type checking on your optional parameters. And it allows for buffer overflows. You should look into the STL fstream and string classes for things like this.

HtH

-D
Thanks for the reply I was able to compile. Now I ran into a previous problem and just possibly you may have solved that one also! Although this program is able to compile, it still runs into an error. That being:

// Scan the number after the tag
fscanf( pFilepointer, "%d", &g_pStartdefines->APItype );

It errors out at that point, meaning I am unable to get past this and initiate any api. Could this be because I am not using STL fstream and string classes? I will look into it. Thanks again.

This topic is closed to new replies.

Advertisement