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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:51:10+00:00 2026-05-30T02:51:10+00:00

so i have a struct call Process_Info struct Process_Info { char name[128]; int pid;

  • 0

so i have a struct call Process_Info

  struct Process_Info {
    char name[128];
    int pid;
    int parent_pid;
    int priority;
    int status;
      };

and an array of Process_Info call info. I set pid in info to an integer, it works but when I try to set name in info to “{kernel}” like this

info[i].name="{kernel}";

and it give me incompatible type in assignment error. I search online it seem i can do this, like in http://www.cs.bu.edu/teaching/cpp/string/array-vs-ptr/, they did char label[] = “Single”; So what am i doing wrong?

  • 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-30T02:51:11+00:00Added an answer on May 30, 2026 at 2:51 am

    The short answer: A C compiler will bake constant strings into the binary, so you need to use strncpy (or strcpy if you aren’t worried about security) to copy “{kernel}” into info[i].name.

    The longer answer: Whenever you write

    char label[] = "Single";
    

    the C compiler will bake the string “Single” into the binary it produces, and make label into a pointer to that string. In C language terms, “Single” is of type const char * and thus cannot be changed in any way. However, you cannot assign a const char * to a char *, since a char * can be modified.

    In other words, you cannot write

    char label[] = "Single";
    label[0] = "T";
    

    because the compiler won’t allow the second line. However, you can change info[i].name by writing something like

    info[i].name[0] = '[';
    

    because info[i].name if of type char *. To solve this problem, you should use strncpy (I referenced a manual page above) to copy the string “{Kernel}” into info[i].name as

    strncpy(info[i].name, "{Kernel}", 256);
    info[i].name[255] = '\0';
    

    which will ensure that you don’t overflow the buffer.

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

Sidebar

Related Questions

I have a struct struct Packet { int senderId; int sequenceNumber; char data[MaxDataSize]; char*
I have a struct that contains pointers: struct foo { char* f; int* d;
I have the next struct struct Board { int width; int height; char **board;
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int
I have this struct: struct Map { public int Size; public Map ( int
If have a struct A { public double[] Data; public int X; } How
Guys I have some silly struct let's call it X and I also have
Ok so I have struct like this typedef struct { float x; float y;
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a
In my driver's file_operations structure, I have: struct file_operations Fops = { read: device_read,

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.