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

  • SEARCH
  • Home
  • 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 655157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:34:23+00:00 2026-05-13T22:34:23+00:00

Why does the following code throw an exception when getting to the second scanf_s

  • 0

Why does the following code throw an exception when getting to the second scanf_s after entering an number to put into the struct.

This by no means represents a complete linked list implementation.

Not sure how to get onto the next scanf_s when having entered the value? Any ideas?

EDIT: Updated code with suggested solution, but still get an AccessViolationException after first scanf_s

Code:

struct node
{
    char name[20];
    int age;
    float height;
    node *nxt;
};

int FillInLinkedList(node* temp)
{

int result;
temp = new node;

printf("Please enter name of the person");
result = scanf_s("%s", temp->name);

printf("Please enter persons age");
result = scanf_s("%d", &temp->age); // Exception here...

printf("Please enter persons height");
result = scanf_s("%f", &temp->height);

temp->nxt = NULL;
if (result >0)
    return  1;
 else return 0;
}

// calling code

int main(array<System::String ^> ^args)
{
  node temp;

  FillInLinkedList(&temp);

...
  • 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-13T22:34:24+00:00Added an answer on May 13, 2026 at 10:34 pm

    You need

    result = scanf_s("%d", &temp->age);
    

    and

    result = scanf_s("%f", &temp->height);
    

    Reason is that sscanf (and friends) requires a pointer to the output variable so it can store the result there.

    BTW, you have a similar problem with the parameter temp of your function. Since you’re changing the pointer (and not just the contents of what it points to), you need to pass a double pointer so that the changes will be visible outside your function:

    int FillInLinkedList(node** temp)
    

    And then of course you’ll have to make the necessary changes inside the function.

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

Sidebar

Related Questions

I'm getting an MDA after running this code for the second time in a
Why does the following code throw an exception? for (int i = 0; i
Why does the following code throw ArrayStoreException ? double[] a = {2.0,3.4,3.6,2.7,5.6}; int[] b
Why does the following Java code snippet throw a StringIndexOutOfBoundsException on the third line
In the following code why does mockTest.ToString() return Null? EDIT: Added comment into example
The following code does not catch an exception, when I try to divide by
Folks -- I am getting the following exception and can't explain why. The number
I'm getting the above exception and error on the following code, which is meant
Noob Question. Stuck on the following code. Getting Default constructor cannot handle exception type
Why does following code snippet doesn't work? It doesn't gives any error, but also

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.