memory allocation in gedit without use of malloc

Asked by vishal panwar

I cant allocate the memory by using the malloc function in c programming.
T he error it gives is" malloc is not defined in the scope".

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gedit Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

You would be better posting this on a programming forum too.

Does your code have:

#include <sys/malloc.h>

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2
Revision history for this message
Larry Jordan (larryjor) said :
#3

     I'm more of a beginner in C, but I guess any of us would have to see what you used a little more... for now, let me ask if you included stdlib.h? The book I use shows a simple example of memory allocation with the following:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#define A_MEGABYTE (1024 * 1024)

int main()
{
     char *some_memory;
     int megabye = A_MEGABYTE;
     int exit_code = EXIT_FAILURE;

     some_memory = (char *)malloc(megabyte);
     if (some_memory != NULL){
          sprintf(some_memory, "HELLO WORLD\n";
          printf("%s", some_memory);
          exit_code = EXIT_SUCCESS);
     }
     exit(exit_code);
}

     This is taken from "Beginning Linux Programming, 4th Edition", by Neil Matthew and Richard Stones. Realize you may not want to show your program, but are you following the format ok?

Can you help with this problem?

Provide an answer of your own, or ask vishal panwar for more information if necessary.

To post a message you must log in.