Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
1 answer

Cant access data after realloc struct vector

I'm using reallocto reduce the size of my vector. I want to loose the last position only. so, if I have 10 positions and I use realloc to allocate enough space for 9 * sizeof(my_struct) will the vector get truncated and keep the old data but the…
PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90
0
votes
1 answer

changing size of array in c using realloc

I've got a problem in ansi-C. I'm trying to make stack in C on arrays. But I've got a problem with functions pop and push - I don't know how to change size of array. I think I can make it somehow using function realloc(), but I dont know how. Can…
aviss
  • 1
  • 1
  • 1
0
votes
1 answer

Why does this realloc() fail?

My first C project is a simple cURL-like HTTP client that retrieves the headers, content, and status of a request sent to a server. It's been working out so far, but it is not finished and I need some help. Memory allocation has been a bit of a…
dylanweber
  • 580
  • 7
  • 19
0
votes
2 answers

Realloc with matrix and automatization

I was wondering why realloc for a char* or whatever 1D array works if I do something like oldpointer=realloc(oldpointer,newsize); But when I try with a 2D char* array it fails. Looking here and there I see that sometimes people use…
ro.nin
  • 121
  • 5
  • 13
0
votes
1 answer

callin' c from lua crashs while reallocating

i got a crazy error within that for-loop matr=realloc(matr, newmax*sizeof(matr*)); for (i=0; i
mkind
  • 2,015
  • 2
  • 20
  • 25
0
votes
1 answer

Realloc and glocal new/delete operator overriding

Stated that there is no C++ equivalent of the C realloc function, I've found in another question that such a thing is automatically managed by std::vector and we should use it instead. I'm fine with it. I guess that, since there is no other way of…
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
0
votes
2 answers

Arrays and malloc in C

Hello I am new to C and I need someone to explain concepts to me. I am a JAVA programmer and I am trying to write a program in C. My current issue is trying to initialize an array with an unknown number. I know in C an array has to be initialized…
user4332856
0
votes
1 answer

Realloc in list implementation sends a SIGABRT signal on third call

typedef struct List { void **data; int dataSize; int count; int capacity; } List; List list_create(int dataSize) { List list; list.data = malloc(dataSize); list.dataSize = dataSize; list.count = 0; list.capacity…
Cains
  • 883
  • 2
  • 13
  • 23
0
votes
1 answer

How do I create a function in C that allows me to split a string based on a delimiter into an array?

I want to create a function in C, so that I can pass the function a string, and a delimiter, and it will return to me an array with the parts of the string split up based on the delimiter. Commonly used to separate a sentence into words. e.g.:…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
0
votes
2 answers

How to recycle and reuse allocated memory?

What I'm working on right now is a state-based parser for any input from a stream. My professor tells me this is the best way to avoid special cases. The way I've got it set up is using functions, and I'm having a little bit of trouble trying to…
Plaidypus
  • 81
  • 9
0
votes
1 answer

Realloc - Realloc do not make smaller char*

OS: Linux CC: GCC 4.8.2 Targer: Change size of char* -> to smaller PROBLEM: Size after change is same... line is string with data... Code fragment: char * tmp = NULL; [...] tmp = malloc(sizeof(char) * 8); strncpy(tmp, line, sizeof(char) *…
Jan Czarny
  • 916
  • 1
  • 11
  • 29
0
votes
1 answer

To Do List, Reallocation in C

I'm doing a homework assignment for Computing II. It's to create a to-do list of tasks in a dynamically created array of strings that can manipulated in a number of ways. One of the ways it needs to be manipulated is through the addition of a task,…
0
votes
4 answers

Why realloc fails with temporary pointer

The following works successfully: char *op, op_temp; op = malloc(len+1); op_temp = op; op = realloc(op, ++len); while the following results in a runtime error: char *op, op_temp; op = malloc(len+1); op_temp = op; op = realloc(op_temp, ++len); Why…
tomol
  • 755
  • 1
  • 6
  • 12
0
votes
1 answer

C Language Dynamic array realloc causes Heap block error message

I just started learning C programming and practicing dynamic array and malloc and realloc. I'm using Visual Studio and the code is in file extension .c But I do not know why realloc is causing the error message "HEAP[Assignment1Start.exe]: Heap…
SpiderWeb
  • 79
  • 6
0
votes
1 answer

How to realloc based on size of array?

Say you malloc enough memory space to hold an array of size 20. The program is running and now I need enough memory for an array of size say 40. I tried to do this using realloc but it doesn't seem to be working. My code is the following(I'm trying…
modsoussi
  • 137
  • 11