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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:36:44+00:00 2026-05-26T15:36:44+00:00

Okay look first thanks for this place :) I would like to create a

  • 0

Okay look first thanks for this place 🙂
I would like to create a piece of shared memory to store 30 structures of the same type, but I am getting errors on compile..

struct nota
{
    int n;
    char text[30];
    char titulo[100];
    char login[20];
}

main(){
     int shmID;
     struct nota *evernota;
     struct nota um;

     shmID = shmget(1009, sizeof(struct nota)*30 , 0666 | IPC_CREAT);

     evernota = shmat(shmID, NULL, 0);

     evernota[0] = &um;  //Declaring one note here to the first position of shm..
     evernota[20] = &um;  //Declaring the same note on the 20 position of shm..

     printf("o meu int é %d\n",evernota[0]->n);  //Here I would get the int n of each structure, that should be 0, because its not initialized..
     printf("o meu int é %d\n",evernota[20]->n);  //and there the same n, because I use the same structure on position 0 and 20..  
}

But I have compile errors, someone see where is the problem??
Thanks alot in advance!!!

  • 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-26T15:36:45+00:00Added an answer on May 26, 2026 at 3:36 pm

    well for starters you need the includes:

    #include <stdio.h>
    #include <string.h>
    #include <sys/shm.h>
    

    then you need the semicolon after struct definition:

    struct nota {
        ...
    };
    

    Add the flag IPC_EXCL, makes shmget fail if the memory key is already in use (use IPC_PRIVATE instead of 1009 to guarantee the memory segment is new). Then a check on shmID != -1 would be nice, and to copy the references use memcopy:

    memcpy(&evernota[0], &um, sizeof(struct nota));  
    memcpy(&evernota[20], &um, sizeof(struct nota));
    

    about the printfs, use the . instead of ->. They will print garbage data, they’re not automatically 0-initialized on allocation, you have to do it by yourself.

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

Sidebar

Related Questions

Okay. I know this looks like the typical Why didn't he just Google it
Have a look at the menus on this page: http://www.pieterdedecker.be/labs/vspwpg/?page_id=96 They look okay in
Still a little gunshy about jQuery. Does this simple popup window script look okay?
Okay so im working on this php image upload system but for some reason
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My
Okay!... I'm facing this for hours now... html <div contenteditable=true style=width: 509px; ></div> <textarea
Okay, it's been such a long day that I am just going to look
I have this piece of code I found on some blog, that's supposed to
Feel like this should be something easy that I'm missing. I have a table

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.