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 7171639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:27:14+00:00 2026-05-28T15:27:14+00:00

I’m teaching myself about structures in C, and am having trouble compiling this code:

  • 0

I’m teaching myself about structures in C, and am having trouble compiling this code:

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

struct Date {
    int Month;
    int Day;
    int Year;
};

void AddDecade(struct Date);

int main(int argc, char *argv[]) {
    struct Date BDay;
    char buffer[50];

    printf("What month were you born? ");
    BDay.Month = atoi(gets_s(buffer, 50));

    printf("What day were you born? ");
    BDay.Day = atoi(gets_s(buffer, 50));

    printf("What year were you born? ");
    BDay.year = atoi(gets_s(buffer, 50));

    printf("You were born on %d, %d, %d?\n", BDay.Month, BDay.Day, BDay.Year);

    AddDecade(BDay);

    printf("You will be 10 years older on %d, %d, %d\n", BDay.Month, BDay.Day, BDay.Year);
}

void AddDecade(struct Date Target) {
    Target.Year += 10;
}

The author of the code compiled it without error on a Windows machine, but on my Linux machine gcc gives the following errors:

07_04_structures2.c: In function ‘main’:

07_04_structures2.c:18:5: warning: passing argument 1 of ‘atoi’
makes pointer from integer without a cast
[enabled by default]

/usr/include/stdlib.h:148:12: note: expected ‘const char *’ but
argument is of type ‘int’

07_04_structures2.c:21:5: warning: passing argument 1 of ‘atoi’ makes
pointer from integer without a cast [enabled by default]

/usr/include/stdlib.h:148:12: note: expected ‘const char *’ but
argument is of type ‘int’

07_04_structures2.c:24:9: error: ‘struct Date’ has no member named
‘year’

07_04_structures2.c:24:5: warning: passing argument 1 of ‘atoi’ makes
pointer from integer without a cast [enabled by default]

/usr/include/stdlib.h:148:12: note: expected ‘const char *’ but
argument is of type ‘int’

Given this line:

BDay.Month = atoi(gets_s(buffer, 50));

My understanding is that gets_s copies a maximum of 50 bytes of input into buffer, and passes a pointer to the variable ‘buffer’, to atoi, but according to this error:

note: expected ‘const char *’ but argument is of type ‘int’

perhaps gets_s is at fault here? I’ve never used it before…

I’d be very thankful for a detailed explanation of what’s wrong, and how to fix it.

Thanks a lot!


Update:

I implemented all of your recommendations and have come up with the following working code:

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

struct Date {
    int Month; 
    int Day;
    int Year;
};

struct Date AddDecade(struct Date);

int main(int argc, char *argv[]) {
    struct Date BDay;
    char buffer[50];
    char *buffer_end;

    printf("What month were you born? ");
    fgets(buffer, sizeof(buffer), stdin);
    BDay.Month = strtol(buffer, &buffer_end, 10);

    printf("What day were you born? ");
    fgets(buffer, sizeof(buffer), stdin);
    BDay.Day = strtol(buffer, &buffer_end, 10);

    printf("What year were you born? ");
    fgets(buffer, sizeof(buffer), stdin);
    BDay.Year = strtol(buffer, &buffer_end, 10);

    printf("You were born on %d, %d, %d?\n", BDay.Month, BDay.Day, BDay.Year);

    BDay = AddDecade(BDay);

    printf("You will be 10 years older on %d, %d, %d\n", BDay.Month, BDay.Day, BDay.Year);
}

struct Date
AddDecade(struct Date Target) {
    Target.Year += 10;
    return Target;
}

This has been a great learning experience for me! Thank you! 🙂

  • 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-05-28T15:27:15+00:00Added an answer on May 28, 2026 at 3:27 pm

    get_s() isn’t implemented in the Linux C library, so the compiler assumes the default of it being a function that returns and int takes whatever (promoted) parameters you pass it.

    You’ll need to recode to avoid using gets_s(). Probably the simplest fix is to use fgets() instead. Change the lines similar to:

    BDay.Month = atoi(gets_s(buffer, 50));
    

    with:

    fgets(buffer, sizeof(buffer), stdin);
    BDay.Month = atoi(buffer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.