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…
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…
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;
…
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;
…
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…
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…
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…
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],…
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…
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…
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…
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…
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…
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…
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;
…