Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
2 answers

Array of Structs memory realloc stderr

I am trying to realloc an array of structs when it runs out of space as I'm putting elements into it but I keep receiving a realloc stderr. The array of struct will eventually have 235,000 elements in it. When I set the initial start size to 100,000…
0
votes
2 answers

Creating function out of realloc() function

I would like to create a function that will reallocate 2D array of typedef struct typedef struct hero_data{ char name[254]; char title[254]; int encoding; int startstr; double incstr; int startdex; double incdex; int…
Beginner C
  • 79
  • 3
  • 12
0
votes
2 answers

Using Strings and Malloc/Realloc

I'll be honest, I'm a complete novice at c. Thus, things like malloc and realloc are alien concepts. I think I have the basics down, but I just can't quite get there 100%. while (int args = scanf("%s", string)) { if (args < 0) break; …
Tyler Sebastian
  • 9,067
  • 6
  • 39
  • 62
0
votes
3 answers

invalid size of struct after realloc

I want to load records from a file into a dynamic array. I have the following code: typedef struct my_data { char name[100]; }my_data; struct my_data *data; void load_data() { struct my_data *temp = NULL; int i = 0; FILE * in; …
Sam Reina
  • 305
  • 1
  • 7
  • 22
0
votes
1 answer

Is malloc/realloc/calloc used?

For C programmers. How can I know if a pointer char *, for example, was initialized by using malloc or realloc? I mean in kind of that function: char* func(char** x){ /* need some reallocating of *x but * *x can be a pointer to const…
Pycz
  • 366
  • 3
  • 12
0
votes
2 answers

Increasing structure size and then resetting them back to original size and increase size again

I am new to C but I am currently working on a C program which I am having an issue with relating to structures and memory allocation. What I have in my code is a permanent while loop which will break out of when a certain condition is met. Within…
Boardy
  • 35,417
  • 104
  • 256
  • 447
0
votes
2 answers

Reallocating memory causes invalid next size

I am working on a project in C, I am very new to C so this may be a very simple answer but I can't find out how I can resolve this issue. What I have is a structure which is defined in the header file in the following way. typedef struct…
Boardy
  • 35,417
  • 104
  • 256
  • 447
0
votes
3 answers

Reading stream char by char

I'm using this function to read, char by char, a text file or a stdin input void readLine(FILE *stream, char **string) { char c; int counter = 0; do { c = fgetc(stream); string[0] = (char *) realloc (string[0],…
GSchimiti
  • 43
  • 1
  • 7
0
votes
1 answer

Access violation at ABABABAB after realloc

I ran into this error and I don't quite understand what happens here. I hope the codesnippet is sufficient to make my point. I am modifying a callback to inject my own data into a response to a server. Basically the callstack looks as…
AnyOneElse
  • 406
  • 2
  • 6
  • 17
0
votes
1 answer

Editing Elements of Original Array, Valgrind and Functional Error

So in my program, I am trying to edit the elements of the original array "frags", which initially, have allocated strings stored in some slots. But I'm not exactly sure how. Over the course of the program, I need to reallocate elements in my…
pyrrhic
  • 1,769
  • 2
  • 15
  • 27
0
votes
3 answers

realloc structure with function in C

My C program is crashing and I am too new to figure it out. It's very simple so far and I imagine the code is enough to figure out what is going wrong. I am simply trying to read a file line by line. I will double the memory of a structure once I…
user2587878
  • 121
  • 3
  • 15
0
votes
4 answers

Error while concatenating the string

I am trying a make a function that appned a string after another string. I am witnessing the following error. Please help. * glibc detected ./a.out: realloc(): invalid old size: 0x00007fff7af0d450 ** // The following code concatenates the orignal…
Akshit
  • 103
  • 5
0
votes
0 answers

Storing value in int array from mysql of type mediumint

I am new to C and working on a project at the moment but I am having an issue. I have a int array which is defined as below: int* SwitchIDs = malloc(sizeof(int)); int* SeizeUTC = malloc(sizeof(int)); int* CorrelationIDs = malloc(sizeof(int)); I…
Boardy
  • 35,417
  • 104
  • 256
  • 447
0
votes
1 answer

realloc pointer change when out of function

i am starting homework about dynamic array, first, I have a 2 dimensional array : int initializeInfo[3][4] ={{77,68,0,0},{96,87,89,78},{70,90,86,0}}; and use pointer to store it: int **ptr = (int**)malloc(3*sizeof(int)); int size = 0; for(int i…
famfamfam
  • 396
  • 3
  • 8
  • 31
0
votes
2 answers

glibc detected realloc(): invalid next size: 0x

This code implement an extensible queue using realloc(), this is only a part of the original code. When I run this get an error: typedef uint32_t u32; typedef uint64_t u64; typedef struct _queue_t *queue_t; struct _queue_t { u32 *array; …
pabloapast
  • 75
  • 8