I am trying to do a function that will store in a char array some information to print on it:
int offset = 0;
size_t size = 1;
char *data = NULL;
data = malloc(sizeof(char));
void create(t_var *var){
size_t sizeLine =…
I am a beginner and am having a really hard time with dynamic memory allocation. If anyone can help me with this problem, I would be really grateful.
I allocate some memory using malloc to an array Node using:
struct nodeT {
int id;
nodeT *parent,…
I can't seem to find a question that matches exactly what I'm doing, so here goes. Below is a cut down version of my C app down to where a problem lies. I know it's ugly code and missing a few error checks but it was just for me to figure out this…
Let's say I have a struct called Thing. If I want to have an array of "Thing", yet it doesn't have a fixed size (dynamic), how do I go about allocating space for it? Do I initially malloc space for the array itself, and then have to realloc space…
Possible Duplicate:
How to handle realloc when it fails due to memory?
Let's say I have an array of pointers
char **pointers_to_pChar = 0;
pointers_to_pChar = (char **)malloc(sizeof(char *) * SIZE);
for (i = 0; i < SIZE; ++i)
{
…
I have a few questions about a piece of code that I have found on web, which is located at http://www.c.happycodings.com/Data_Structures/code9.html.
Why is strarray defined as **?
Do we have to first malloc() the array, and then malloc() each…
Possible Duplicate:
realloc and malloc functions
#include
#include
void main()
{
int *p;
p = malloc(6);
p = realloc(p, 10);
if (p == NULL)
{
printf("error"); // when does p point to null consider i have enough…
I'm trying to dynamically allocate memory for (what is essentially) a 2-dimensional array of chars - i.e - an array of strings.
My code is as follows:
typedef char LineType[MAX_CHARS+1];
LineType* lines;
int c = 0;
int N = 2;
lines = (LineType *)…
When trying to reallocate memory I crash when using this code:
//value of i is currently 4096
while((c = recv(sock, htmlbff + q, MAXDATASIZE, 0)) > 0)
{
if((i - q) < MAXDATASIZE)
{
i *= 2;
if(!(tmp = realloc(htmlbff,…
Is there any way i can delete the partial memory of the pointer.?
for example
char *c = new char[1000];
sprintf(c,"this is it");
As it can be seen a lot of memory is getting wasted here. can I free the memory more than the required.?
I have declared double pointer in main and allocate memory like this
char **group_name;
group_name = realloc( NULL, 1);
group_name[0] = realloc(NULL ,20);
I have passed this array to a function,
group_count(object, count, group_name);
which uses…
I have to read a matrix of double, handling its values and insert them in a new matrix, whose one of its dimension is unkwown at the beginning.
In a static memory allocation, my code is:
#include
void mexFunction( int nlhs, mxArray *plhs[],…
I have to write a program that stores and prints out integers from memory. I have to use realloc. Basically, the program allocates size for 2 ints. When input is given 2 ints it should reallocate space for 1 more int and prints out double. Next,…
Here i am getting some problems in realloc or free in message queue example.
In below program i got error of double free or corruption at the time of last message received from the message queue.
I send 10 messages in message queue and i received 10…
I'm having some serious trouble with this function: When the trace reaches the realloc, it blows up. I've checked similar questions on this subject but nothing came out. I hope you can help me. Do you see anything wrong?
char **tokenizepath(char…