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…
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…
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…
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…
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…
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…
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…
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.:…
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…
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,…
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…
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…
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…