error in debugging C code

Reply

Join Date: Jul 2009
Posts: 11
Reputation: selsium has a little shameless behaviour in the past 
Solved Threads: 0
selsium selsium is offline Offline
Newbie Poster

error in debugging C code

 
-1
  #1
Sep 3rd, 2009
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--------------------------------

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define ARG_ERROR 1
  5.  
  6. int main(int argc, char **argv)
  7. {
  8. FILE *fperr;
  9. char CARTERR[255];
  10. while(argc--)
  11. printf("%s\n", *argv++);
  12. #ifdef WIN32
  13. sprintf( CARTERR,"%s\\%s",getenv("GVS"),_CARTERR);
  14. #endif
  15.  
  16. if( argc < 3) {
  17. printf( "Error in document\n");
  18. fperr = fopen( CARTERR,"w");
  19. fprintf( fperr,"%d:Error %s",ARG_ERROR);
  20. fclose( fperr);
  21. return( ARG_ERROR);
  22. }
  23.  
  24. exit(EXIT_SUCCESS);
  25. }
Last edited by John A; Sep 3rd, 2009 at 8:51 pm. Reason: added code tags
Attached Thumbnails
error.JPG  
|Selva|
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,400
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 113
Sponsor
William Hemsworth William Hemsworth is online now Online
Nearly a Posting Virtuoso

Re: error in debugging C code

 
0
  #2
Sep 3rd, 2009
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.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: error in debugging C code

 
0
  #3
Sep 3rd, 2009
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 11
Reputation: selsium has a little shameless behaviour in the past 
Solved Threads: 0
selsium selsium is offline Offline
Newbie Poster

Re: error in debugging C code

 
0
  #4
Sep 4th, 2009
Originally Posted by Dave Sinkula View Post
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?
|Selva|
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: error in debugging C code

 
0
  #5
Sep 4th, 2009
Originally Posted by selsium View Post
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 .
Hopefully my last post makes sense now.

Change #ifdef WIN32 to #if 1 for a moment.
  1. main.c: In function `main':
  2. 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:
  1. sprintf( CARTERR,"%s\\%s",getenv("GVS"),_CARTERR);
Without that line, what file are you opening?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 309
Reputation: NicAx64 will become famous soon enough NicAx64 will become famous soon enough 
Solved Threads: 18
NicAx64's Avatar
NicAx64 NicAx64 is offline Offline
Posting Whiz

Re: error in debugging C code

 
-1
  #6
Sep 4th, 2009
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.
Last edited by NicAx64; Sep 4th, 2009 at 12:41 pm.
Nothing like a kernel pannic !
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 309
Reputation: NicAx64 will become famous soon enough NicAx64 will become famous soon enough 
Solved Threads: 18
NicAx64's Avatar
NicAx64 NicAx64 is offline Offline
Posting Whiz

Re: error in debugging C code

 
-1
  #7
Sep 4th, 2009
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 __ .
Nothing like a kernel pannic !
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: error in debugging C code

 
0
  #8
Sep 4th, 2009
http://predef.sourceforge.net/preos.html#sec24
Originally Posted by NicAx64 View Post
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC