Thread: Results in Debug and Release mode are different

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User jaro's Avatar
    Join Date
    Mar 2006
    Location
    In my Parent House
    Posts
    34

    Results in Debug and Release mode are different

    Hi!,

    I've created three functions that would work together in order to generate a date is string YYYY-MM-DD format.
    The code works fine in Debug mode.The problem is when I try to run this code in the Release mode.
    It (the program) gives me two different results when I run it in Debug and Release mode.
    And no compile error and warning are present when I compile it in those two modes respectively.


    here is the code
    Code:
    #include <string.h>
    #include <stdio.h>
    #include <time.h>
    
    #define HOUR 261
    #define MINUTE 262
    #define DAY 263
    #define MONTH 264
    #define YEAR 265
    
    
    void padUpString(char *str, char* filler, int len, int fillAtTheEnd)
    {
    
    	int i;
    	char newstr[50]="";
    	
    	int strLen = strlen(str);
    	int diff = len - strLen;
    
    
    	if (strLen < len)
    	{
    		for (i=0; i< len ; i++)
    		{
    			if (fillAtTheEnd)
    			{
    				if( i >= strLen) *(str+strLen++)=*filler;
    			}else
    			{
    			     if( i < diff) strcat(newstr,filler);
    
    			}
    		}
    		if (!fillAtTheEnd)
    		{
    			strcat(newstr,str);
    			strcpy(str,newstr);
    		}
    	}
    }
    
    
    int getCurrentTimeValue(int timeElement)
    {
    	struct tm *tm_today;
    	time_t t;
    
    	t = time(NULL);
    	tm_today = localtime(&t);
    	//printf("timeElement is %d\n",timeElement);
    
    	if (timeElement == HOUR)
    	{
    		return tm_today->tm_hour;
    	}
    	if (timeElement == MINUTE)
    	{
    		return tm_today->tm_min;
    	}
    	if (timeElement == DAY)
    	{
    		//printf("DAY is %d\n",timeElement); //for debug purposes
    		return tm_today->tm_mday;
    	}
    	if (timeElement == MONTH)
    	{
    		//printf("MONTH is %d\n",timeElement);//for debug purposes
    		return tm_today->tm_mon + 1;
    	}
    	if (timeElement == YEAR)
    	{
    		//printf("YEAR is %d\n",timeElement);//for debug purposes
    		return tm_today->tm_year + 1900;
    	}
    	return -1;
    }
    
    
    void getProcessDate(char *procDate)
    {
    	//YYYY-MM-DD
    	char currentTime[11];
    	char year[4];
    	char day[2];
    	char month[2];
    
    	sprintf(year,"%d",getCurrentTimeValue(YEAR));
    	sprintf(month,"%d",getCurrentTimeValue(MONTH));
    	sprintf(day,"%d",getCurrentTimeValue(DAY));
    
    	printf("\nCheck date\n"); // for testing purpose only
    	printf("year [%s]\n",year);
    	printf("month [%s]\n",month);
    	printf("day [%s]\n",day);
    
    
    	padUpString(month,"0",2,0);
    	padUpString(day,"0",2,0);
    
    	printf("\nAfter padding\n");// for testing purpose only
    	printf("month [%s]\n",month);
    	printf("day [%s]\n",day);
    
    	sprintf(currentTime,"%s-%s-%s",year,month,day);
    	currentTime[10] = '\0';
    	memcpy(procDate,currentTime,sizeof(currentTime));
    }
    
    
    int main()
    {
    	char date[30];
    	getProcessDate(date);
    	printf("%s\n",date);
    	return 0;
    
    }

    the output
    Debug Mode
    Check date
    year [2006]
    month [5]
    day [24]

    After padding
    month [05]
    day [24]
    2006-05-24
    Release Mode
    Check date
    year [2006]
    month []
    day [24]

    After padding
    month [00]
    day [2400]
    -00-2400

    as you can see the "month" in Release mode is blank,which I suspect is the one causing the problem.

    Does anyone know why the results are different?
    and how would I fix such problem?

    I'm using MVC6 in Win2K

    Regards,
    jaro
    Last edited by jaro; 05-24-2006 at 05:20 AM. Reason: forgot to include tool being used

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-16-2006, 07:11 PM
  2. release vs debug mode
    By bithub in forum Tech Board
    Replies: 2
    Last Post: 05-10-2006, 03:31 PM
  3. Release vs. Debug mode builds
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 11-10-2005, 04:41 PM
  4. Debug Mode Vs. Release Mode
    By incognito in forum Tech Board
    Replies: 5
    Last Post: 12-18-2003, 04:06 PM
  5. 2min in debug mode, 3sec in release!
    By glUser3f in forum C++ Programming
    Replies: 9
    Last Post: 10-03-2003, 01:00 PM