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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:57:49+00:00 2026-05-29T20:57:49+00:00

I am pretty new to programming on Linux. I am trying to implement a

  • 0

I am pretty new to programming on Linux. I am trying to implement a message queue in one of my assignments. But I am not able to do it. The code is as follows :

#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <linux/sched.h>
#include <stdlib.h>
#include <string.h>

typedef long MSISDN;
typedef struct 
{
   long mtype;
   long mtext;
}msgbuf;

void init(int qid,int key) {
   qid = msgget(key,IPC_CREAT|0666);
}

void sendMsg(long t_ype, long buf, int len, int qid) {

   int length = sizeof(long) + sizeof(MSISDN);
   msgbuf *p = malloc(length);
   p->mtype = t_ype;
   fputc('2',stderr);
   void* tosend = (void*) buff;
   fputc('3',stderr);

   memcpy(p->mtext,tosend,length);

   fputc('4',stderr);
   msgsnd(qid,p,length,IPC_NOWAIT);
   free(p);
}



void main()
{
   int qid;
   int key = 1111;
   int len= sizeof(MSISDN); 
   long type_1=1;
   long send = 12345;

   init(qid,key);
   fputc('1',stderr);
   sendMsg(type_1,send,len,qid);

   getchar();
}

The problem is memcpy is not working . I am getting a warning :

. warning: passing argument 1 of ‘memcpy’ makes pointer from integer without a cast [enabled by default]

Also when I run the code it gets a SIGSEGV signal at the memcpy. I think I am not getting the typecast correctly.

  • 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-29T20:57:50+00:00Added an answer on May 29, 2026 at 8:57 pm

    It’s not the typecast, it’s the argument itself. p->mtext is a long, not a pointer. You need to send the address of p->mtext as the dest argument to memcpy. You’re getting the segfault because memcpy is trying to write to the memory address pointed to by p->mtext, which is clearly not in your process’ address space.

    That’s the reason – since this is a homework assignment, I’ll leave the fixing of the code up to you.

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

Sidebar

Related Questions

I'm pretty new to Android programming, and I've looked around but haven't been able
Alright I'm pretty new to programming and stuff and I'm now trying to code
I'm pretty new to programming for Linux environments, so I don't exactly know what
I've done a fair bit of mysql php programming but am pretty new to
I am pretty much new to linux programming. I want to create a log
I'm pretty new to programming but I feel I'm getting the hang of it
Pretty new to Java programming, but I'm having trouble getting this to run. I
I'm pretty new to programming, and I'm creating a simple text-based game.> I'm wondering
I'm pretty new to web programming, reading a book on ASP.NET, and I notice
I'm pretty new to Python programming and would appreciate some help to a problem

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.