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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:13:10+00:00 2026-06-14T12:13:10+00:00

I have a stuct in C, and I use a function to get the

  • 0

I have a stuct in C, and I use a function to get the values for the structure from the user. Below is my structure.

typedef struct {
    char    *name;
    char    *chemical_symbol;
    char    *class;
    int     atomic_number;
    double  atomic_weight;
    int     *electrons;
} element_t;

This is the function I am using to get the values from the user. The problem lies in this function after asking for the chemical symbol. I get Bus Error: 10. My understanding of a bus error is when the processor cant attempt the memory access. Any help is appreciated. Thank you!

element_t scan_element() {

    element_t element;

    printf ("Enter New Element Information:\n\n");

    printf("Element Name: ");
    scanf("%s", element.name);

    printf("Element Chemical Symbol: ");
    scanf("%s", element.chemical_symbol);

    printf("Element Class: ");
    scanf("%s", element.class);

    printf("Element Atomic Number: ");
    scanf("%d", &element.atomic_number);

    printf("Element Atomic Weight: ");
    scanf("%lf", &element.atmoic_weight);

    printf("Element Electrons: ");
    scanf("%p", &element.electrons);

    return(element);
}
  • 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-14T12:13:12+00:00Added an answer on June 14, 2026 at 12:13 pm
    printf("Element Name: ");
    scanf("%s", element.name);
    

    You have to allocate memory for the object pointed by element.name for example by using malloc. Without proper allocation element.name is an invalid pointer.

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

Sidebar

Related Questions

I have a structure: typedef struct { LogLevel level; char message[255]; } LogMessage; I
I have a linked list structure: struct SomeLinkedList { const char* bar; int lots_of_interesting_stuff_in_here;
I have a structure which contains character array on C side stuct s {
Ok so I have struct like this typedef struct { float x; float y;
In my driver's file_operations structure, I have: struct file_operations Fops = { read: device_read,
I have a large application containing chained function calls, like this: subsystem. do_stuff(cfg().get(x)). do_stuff(cfg().get(y));
I'm trying to read the bitmap header. I have defined the following struct: typedef
I have a simple struct: typedef struct { void *things; int sizeOfThings; } Demo;
I want to reproduce a get style function from C++ in a C program.
I'd like to use the folowing function to convert from Joda Time to Unix

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.