Hi all,

First of all Thanks for all your last responses ,

Here I have one problem in debugging the below code.
It builds without any errors but it doesn't debugg or says some errors.
I created a exe file and when I try to run the file it doesn't run. It doesn't create a file in the C:\Temp drive
Any one could debug this?

I debugged this code in VS2005 as C project. Is there any change to be made in the system environmental set up? Any change in the VS studio settings?

Anyone help me? I am facing this problem last 48 hrs.

here, GVS = C:\temp

-------------------------------------------------test2.cpp--------------------------------

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

#define ARG_ERROR 1

int main(int argc, char **argv)
{
	FILE *fperr;
	char CARTERR[255];
        while(argc--)
                printf("%s\n", *argv++);
#ifdef WIN32
	sprintf( CARTERR,"%s\\%s",getenv("GVS"),_CARTERR);
#endif

if( argc < 3) {	
		printf( "Error in document\n");
		fperr = fopen( CARTERR,"w");
		fprintf( fperr,"%d:Error %s",ARG_ERROR);
		fclose( fperr);
		return( ARG_ERROR);
	}

        exit(EXIT_SUCCESS);
}
Comments
10 posts, no code tags, have a cookie

Not getting an error for the undefined _CARTERR should indicate that WIN32 is not defined. So CARTERR is never filled with a string. So you try to open a file given by an undefined filename. This likely fails, but you don't check for success. So you probably try to fprintf to NULL.

Adding error-checking code would have caught this.

Not getting an error for the undefined _CARTERR should indicate that WIN32 is not defined. So CARTERR is never filled with a string. So you try to open a file given by an undefined filename. This likely fails, but you don't check for success. So you probably try to fprintf to NULL.

Adding error-checking code would have caught this.

I have defined CARTERR as char CARTERR[255]; so I din't get the error or warining !

I cant understand what you mean in the above lines. Could you explain more?

I have defined CARTERR as char CARTERR[255]; so I din't get the error or warining !

I cant understand what you mean in the above lines. Could you explain more?

Sure. When I said _CARTERR I meant _CARTERR , not CARTERR . :P
Hopefully my last post makes sense now. :)

Change #ifdef WIN32 to #if 1 for a moment.

main.c: In function `main':
main.c:13: error: `_CARTERR' undeclared (first use in this function)

Then change it to #if 0 . Which attempted build matches the output you see for #ifdef WIN32 ? For me, it matches the #if 0 case. Which tells me that this line is not compiled:

sprintf( CARTERR,"%s\\%s",getenv("GVS"),_CARTERR);

Without that line, what file are you opening?

idea: you can use the -E option to tell the compiler to just preprocess only.
Edit: in vs use the /E to preprocess to the stdout then use the '>' to write it to a file.

Then change it to #if 0 . Which attempted build matches the output you see for #ifdef WIN32 ? For me, it matches the #if 0 case. Which tells me that this line is not compiled:

may be __WIN32__ is what you originally mean , see isn't this is a typo ?Normally preprocessor macros that are used by the compiler
or linker internally does start with _ or __ .

This article has been dead for over six months. Start a new discussion instead.