I'm having trouble implementing realloc in a very basic way.
I'm trying to expand the region of memory at **ret, which is pointing to an array of structs
with ret = realloc(ret, newsize); and based on my debug strings I know newsize is correctly…
I have developed this program which is a maze for a uni portfolio I have to do.
I am having issues with an array of pointers to 'path' structures.
I want to be able to dynamically change the size of the array with add_path.
But whilst running the…
The function may move the memory block to a new location, in which case the new location is returned.
For example I have a pointer to an array:
int *arr; // somewhere next it initialized, filled with elements and etc
Somewhere I need to:
void*…
I have code receiving string data from a socket which crashes on the first iteration:
int size_data = 1024*sizeof(char);
char *data = malloc(size_data);
char *data_aux;
int br_aux=0;
int *nptr;
memset(&data[0], 0, size_data);
int br =…
I found out today that when I try to free a pointer that has been reallocated the program crashes and prints "Segmentation Fault".
A realloc() is called on this pointer (array) in order to sizeup the array and merge the old array and another…
I would like to reallocate an array of string with a function. I write a very simple program to demonstrate here. I expect to get the letter "b" to be output but I get NULL.
void gain_memory(char ***ptr) {
*ptr = (char **) realloc(*ptr,…
When I compile and run this code, I get an error. The error message is:
realloc(): invalid next size: 0x0000000002119010
The file input has about 4000 words.
I debugged it, but I can not find any problem.
#include
#include…
I'm trying to allocate some memory with realloc(). This works so far. But if I want to assign the allocated memory to a pointer in a struct variable, I get a segmentation fault:
// in header
typedef struct {
int a;
char test[20];
}…
I have following code that is working fine in my development environment but when the code is moved to production server it give oracle "Heap Consistency Error".
Can you please let me know how to debug this and reason for this?
if…
I am having trouble with a struct array. I need to read in a text file line by line, and compare the values side by side. For example "Mama" would return 2 ma , 1 am because you have ma- am- ma. I have a struct:
typedef struct{
char first,…
This is a homework assignment so I don't want to post any code, but I'm pretty stumped with the bug that I have.
Currently I have a array that has been malloced and am copying the pointer to the array. Now, I can memcpy and memmove with this array…
enter code herei was watching a video in data structures in C , and when i understand the abstract view of the concept i go try implementing it without watching the implementation in the video , and what i implement wasn't in the video, the video…
I when running the following code,I get Realloc() Error : invalid next size error
#include
#include
#include
#define ENLRAGE_SIZE(size) size = size + 10
int checkEndOfFile();
int numIsInArray(int *arr, int…
So, I am trying to copy char per char of a file in a chunk of memory that expands accordingly with the file's size... At the end the code print all ok, but if I use valgrind it will run forever.
#include
#include
#include…
general question here.
I came across a program that has one 2d array like this ps[i][j]. The problem is that i know the size of the j which is 3 but i dont know the size of i (hence the reason i want to use malloc and free(). How can i use the…