954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

error in debugging C code

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);
}
Attachments error.JPG 47.28KB
selsium
Newbie Poster
13 posts since Jul 2009
Reputation Points: 3
Solved Threads: 0
 

I'm surprised you figured out how to attach images. You've been here long enough to know how code-tags work, so please use them.

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

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.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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?

selsium
Newbie Poster
13 posts since Jul 2009
Reputation Points: 3
Solved Threads: 0
 

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?

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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.

NicAx64
Posting Pro
536 posts since Mar 2009
Reputation Points: 86
Solved Threads: 44
 
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 __ .

NicAx64
Posting Pro
536 posts since Mar 2009
Reputation Points: 86
Solved Threads: 44
 

http://predef.sourceforge.net/preos.html#sec24
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 __ .
No. I meant exactly what I said.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You