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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:53:55+00:00 2026-06-01T04:53:55+00:00

Getting a segmentation fault for the following code. Please advise. struct columns { char*

  • 0

Getting a segmentation fault for the following code. Please advise.

struct columns {
      char* c_name;
      char* c_type;
      char* c_size;
};

int main(int argc, char* argv[])
{
  int column_num = 3;
  struct columns col[10];
  //columns *col = (columns*) malloc (sizeof(columns) * column_num);
  strcpy(col[0].c_name, "PSID");
  strcpy(col[0].c_type, "INT");
  strcpy(col[0].c_size, "4");
}

I am using 2 ways to allocate space for columns structure but continue to get a segmentation fault. Am I missing something?

  • 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-01T04:53:56+00:00Added an answer on June 1, 2026 at 4:53 am

    Try this (strdup takes care of storage but remember to free when you are done):

    struct columns {
      char* c_name;
      char* c_type;
      char* c_size;
    };
    
    int main(int argc, char* argv[])
    {
      int column_num = 3;
      struct columns col[10];
    
      col[0].c_name = strdup("PSID");
      col[0].c_type = strdup("INT");
      col[0].c_size = strdup("4");
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a segmentation fault with the following code after adding structs to
I'm getting a segmentation fault trying to compile the following code. My question is,
I am getting a strange result in the following C code. int main() {
Possible Duplicate: getting segmentation fault in a small c program Here's my code: char
I am getting a Segmentation fault (core dumped) run-time error with the following code:
I am wondering why am I getting segmentation fault in the below code. int
I am getting a segmentation fault in the following code: void print_stack(Node * root)
Getting a weird segmentation fault on following code when I try to pass a
why the following code shows segmentation fault? int CreateRawSocket(int protocol_to_sniff) { int rawsock; if((rawsock
I am getting segmentation fault in this code but i cant figure out why.

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.