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

C Dynamic array that expands in size using realloc Error: Invalid next-size

I am working on a project for school below illustrates a simpler general idea of what I'm trying to achieve. Basically What i would like to do is the following: -Ask user for a number(check!) -Create a dynamic array that stores these numbers…
0
votes
1 answer

double free or corruption(fasttop) error/segmentation fault in C

I'm trying to dynamically allocate an array to read user input from the command line. It works 99/100 times, but if I type in a bunch of characters repeatedly I will sometimes get a segmentation fault error OR a double free or corruption(fasttop)…
Jamie Yang
  • 13
  • 2
0
votes
2 answers

Realloc behaviour using a pointer-to-pointer

I don't understand why when I run this code, the printf statements aren't working. Here is the code: typedef struct list { int n; struct list *next; }List; List **head; List *tmp=malloc(sizeof(List)); tmp->n=34; tmp->next=NULL; List…
Luca
  • 55
  • 7
0
votes
1 answer

My code can't reallocate memory (realloc())

I've asked to write code that checks the biggest word in the text file(file1.txt) and write all the words with that size to another text file(file1a.txt) but it says that I have a realloc problem...if I write only one big word in the file1.txt it…
0
votes
2 answers

realloc an array of pointers is doing nothing

I have an array of strings, and I would like to extand it when it no longer has NULL pointers (meaning the array is full). I have tried realloc with no success, I think i'm not thinking right pointer-wise. Here is my code: int storage; //global,…
Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
0
votes
2 answers

How to add the data After reallocating a memory using a realloc() function?

Consider I have a string called "bhuvanesh" , to store that string , Initially allocate the memory using malloc() char *ptr=(char *)malloc(sizeof("bhuvanesh")); sprintf(ptr,"bhuvanesh"); Then I want to add the string with the previously…
Bhuvanesh
  • 1,269
  • 1
  • 15
  • 25
0
votes
2 answers

Move pointer and realloc, C

I'm trying to code a buffer for an input file. The Buffer should always contain a defined amount of data. If a few bytes of the data were used, the buffer should read data from the file until it has the defined size again. const int bufsize =…
deadman
  • 43
  • 1
  • 1
  • 4
0
votes
1 answer

Insert two new rows in 2d array

guys :) I have a 2d dynamic array and I need to find the biggest and the smallest number in every column. I have to insert 2 new lines (for max and min) in my array but it seems that my realloc is not working fine. Please, tell me what I am doing…
0
votes
1 answer

Implementation of Split function in C, reallocation doesn't have effect

i try to implement a split function to split a string with a caracter like in java. But my function need to stock the splited string in tab with 2 dimensions (the tab is in parameters). And my function need to return the numbers of arg. So i pass an…
Timo
  • 497
  • 10
  • 21
0
votes
1 answer

List with a head as double pointer

If i have a list of lists as typedef Struct b { int b; Struct b *next; }B; typedef Struct a { int a; Struct a *next; B *link; }A; and if i develop the data structure following this scheme.. I use a double pointer as head for B for keep track of…
Luca
  • 55
  • 7
0
votes
3 answers

Data writes over after realloc

I a function that allows you to add question to a game. I use realloc to increase the memory so i can store more questions. Script: struct Question* AddQuestions(int* amountQuest){ struct Question* questionsLocation = NULL; int startQuestion…
Olof
  • 776
  • 2
  • 14
  • 33
0
votes
2 answers

C - Dynamic array handling advice

I am currently learning C, as someone, who has quite a bit of experience in more high-level languages than that. After considering some of your comments and doing a bit more testing and fidelling, I came up with a better solution (scroll…
Hr. Rabe
  • 47
  • 5
0
votes
1 answer

valgrind report strange memory usage

I have a large array and I expand it with realloc() and use valgrind to see memory usage. here is minimal example: #include #include #define PASSES 1024 * 2 #define MEMTOALLOC 1024 * 1024 int main(void) { void *remem…
Nick
  • 9,962
  • 4
  • 42
  • 80
0
votes
1 answer

Trouble with realloc

I'm using the realloc function in my program but it is not working properly. Indeed, the call to realloc work 2 times out of 3 during the last call of realloc i get the following message: "* Error in `./sat': realloc(): invalid next size:…
ryuzakinho
  • 1,891
  • 3
  • 21
  • 35
0
votes
3 answers

My realloc function return Segmentation fault

I wrote function - malloc, free and realloc The malloc function work fine. The problem is in the function of the realloc it returns me Segmentation fault and I do not know why this is happening. I would be happy if you help me to Understand why this…