Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:01:37+00:00 2026-06-12T07:01:37+00:00

Hello I am new here and programming in C. I didn’t want to ask

  • 0

Hello I am new here and programming in C. I didn’t want to ask something that you may consider simple but I have asked my classmates and even my programming teacher to see if they can find the error but until today they couldn’t find it (them).

But first let me describe what I know, it says:

“Run-Time Check Failure #2 – Stack variable “d” (and sometimes m and
other y)
was corrupted “.

I made my job trying to debug it but the problem is always showed on the last codeline (of the main body), so I couldn’t find exactly where the problem is, here I attach the code, and I would be very happy if you find the problem and explain me the reason why I get it (to don’t repeat the same mistakes in future) =D.

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

/* Type Declaration */
#define true 1
#define false 0
typedef char boolean;

/* Functions declaration */

boolean test( short int d, short int m, long int y );
boolean nextday( short int d, short int m , long int y );

int main( void )
{
    /* Variables initialization */
    short int d = 0, m = 0; 
    long int y = 0;

    do {
        /* Data by user*/
        printf( "Ingrese el numero de año: " );
        scanf( "%ld", &y );
    }   while ( y < 0 );

    do {
        printf( "Ingrese el numero de mes: " );
        scanf( "%d", &m );  
    }   while ( m < 1 || m > 12 );

    do {
        printf( "Ingrese el numero de dia: " );
        scanf( "%d", &d );
    }   while ( d < 01 || ( test( d, m, y ) == false ) ); // If the data is wrong then re-type the data


    // If the nextday function return value is true then the next day is 01, if not just sum a day
    if ( nextday ( d, m, y ) == true ) { 
        d = 01;

        // If we start a new year the new month must be 01-01-01.
        if ( m == 12 ) {
            m = 01;
            y++;
        }

        // Just increase the month for any other month
        else {
            m++;
        }
    }

    else {
        d++;
    }

    printf( "Mañana será: %d-%d-%ld\n", d, m, y );

    return 0;
}

boolean test( short int d, short int m, long int y ){
    int max;

    switch(m) {
        case 1:       
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            max = 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            max = 30;
            break;
        case 2:
            if ( y % 400 == 0 ){
                max = 29;
            }
            else if ( y % 100 == 0 ){
                max = 28;
            }
            else if ( y % 4 == 0 ){
                max = 29;
            }
            else {
                max = 28;
            }
            break;
    }
    if ( d <= max ){
        return true;
    }
    else {
        return false;
    }
}

boolean nextday( short int d, short int m, long int y ) {

    boolean x;

    // If it's 28-02 in a secular year * 4 then it's a leap-year. (so it has 29 days)
    if  ( m == 2 && d == 28 && y % 400 == 0 ) {
        x = false;
    }

    // If it is an end of century but it isn't 4 multiply then it only has 28 days.
    else if ( m == 2 && d == 28 && y % 100 == 0 ) { 
        x = true;
    }

    // If it just a leap year it has 29 days.
    else if ( m == 2 && d == 28 && y % 4 == 0 ) { 
        x = false;
    }

    //If it's the last day of February and it's a leap year.
    else if ( m == 2 && d == 29 && y % 4 == 0 ){
        x = true;
    }

    // If we are in the end of the month.
    else if ( ( d == 30 && ( m == 4 || m == 6 || m == 9 || m == 11 ) ) || 
                d == 31 ) {  
        x = true;
    }

    // Then if it is another day just sum a day
    else {
        x = false;
    }

    return x;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:01:38+00:00Added an answer on June 12, 2026 at 7:01 am

    You need to use:

    scanf( "%hd", &m );
    scanf( "%hd", &d );
    

    since they are short int’s.

    Using “%d” you are basically loading an int size variable in a small int storage space.

    An int is usually 4 bytes while small int is 2 bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello I am new here and in programming as well. Today I have been
Hello I'm new to android programming. I would like to ask how can I
Hello im new to programming, im trying to construct my first simple application, im
I have an application that calls Email hello = new Email(appropriate constructor); hello.Email_Send(); I'm
hello i am new here and i hope i don`t post in a wrong
I am new here so hello. I am using ASP.NET 4 and I am
hello im new to python and have been reading over the documentation and am
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the
Hello I'm new to Joomla and I want to change the way an account
hello I'm new to PHP programming and I migrated from ASP .net to PHP..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.