Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
4 answers

Dynamic Arrays of Struct

#include #include struct ver{ double x; double y; }; struct ver *v=NULL; int main(){ v=(struct ver*)realloc(v,1*sizeof(struct ver)); v[0].x=1.444; v[0].y=1.555; v[1].x=1.333; v[1].y=1.222; …
0
votes
2 answers

Dynamic memory allocation with int array

I have an assignment in which I have to accept an input from the user. I can't use a linked list, only an array, so my plan is: Alloc some memory. If we need to realloc, meaning that I reached the number of cells allocated: Try to realloc. If…
Assaf
  • 1,112
  • 4
  • 14
  • 35
0
votes
1 answer

valgrind reporting errors and definitely lost when using realloc()

The following are two functions in which the first one tries to allocate and subsequently reallocate memory for an array of pointers depending on the count value. The second function tries to concatenate the last string onwards to the first string…
Chris Petrus
  • 193
  • 1
  • 3
  • 15
0
votes
1 answer

Why does realloc need two pointers? Handling a return of NULL?

I think I know but I don't want to continue my work being incorrect. Most examples you see are... char* temp; char* temp1; temp = malloc(10, sizeof(char); temp1 = realloc(temp, 11*sizeof(char)); Now I am assuming that you don't use... temp =…
JoeManiaci
  • 435
  • 3
  • 15
0
votes
1 answer

Glibc error with realloc: Invalid next size

int i = 0; player_t** matchArray = malloc(sizeof(player_t**)); player_t *currentPlayer = playerList; while(currentPlayer != NULL) { if( strcmp(currentPlayer->nameLast, name) == 0 ) { matchArray = realloc(matchArray, sizeof(matchArray) +…
user2893045
  • 59
  • 1
  • 6
0
votes
2 answers

C : Increase Dynamic Array by one in a loop

I would like to know why I can't reach to increase my array size by only one in a while loop. Here is my code : void pb_memory(void){ printf("ERROR : memory problem !\n"); system("PAUSE"); exit(EXIT_FAILURE); } int main(int argc, char…
Dovakin940
  • 63
  • 6
0
votes
1 answer

Compare same words

I'm new in programming in C and I got 2 problems. I have two string, then I need to split them into words and find out if both strings contains same words. I will explain it with my code. Input: "He said he would do it." "IT said: 'He would do…
Grim
  • 37
  • 2
  • 10
0
votes
1 answer

Realloc concerns

I'm currently helping a friend with his assignments from his university, and have a moral dilemma regarding the behaviour of realloc when passing a NULL pointer (manuals say it should work exactly as a normal malloc). So here's the code: #include…
fxjade
  • 15
  • 4
0
votes
2 answers

Realloc in C for structs containing dynamic array of structs

Issues with reallocing the items list. I am trying to add items into the testList structs items, but i am getting memory address errors when trying to add or print the values for the individual ListItems. Any help would be greatly…
0
votes
5 answers

new and reallocating memory

new[] doesn't support change the size of allocated memory, does it? For example, I allocated memory with new[] for buffer (array of char) and I want to get the additional memory. Should I use malloc/realloc instead in this case?
Dmitry
  • 47
  • 4
0
votes
1 answer

what is wrong with this realloc use

I'm trying to get unlimited input from user, using realloc. this is what i've done so far: int getCharactersFromUser(char* arr,char terminator) { char c = getch(); int length =0; while(c!=terminator) { arr = realloc(arr, sizeof…
limido
  • 327
  • 2
  • 14
0
votes
1 answer

Valgrind reports memory leak for realloc call. But unable to understand why

I have a struct as follows: typedef struct somefruits{ struct pine abc; int xyz; }pm; struct pine { unsigned char *ch; unsigned char *data; unsigned int a; } int function(unsigned int nfruits, pm **outfruits) { pm *fruits =…
user1357576
  • 389
  • 2
  • 3
  • 17
0
votes
1 answer

C Valgrind - Conditional jump depends on unitialitialised value

i want to repair one error.. Valgrind says me this: ==9203== 1 errors in context 1 of 1: ==9203== Conditional jump or move depends on uninitialised value(s) ==9203== at 0x4C2D64A: strncat (in…
0
votes
1 answer

I get segmentation fault when I try to insert new row into 2D-Array using realloc

When ever the program finds a row in witch the first element's last number and the last element's last number divide by 2, then it should add other row to the matrix. I need to do this using dynamic allocation. Here is the code: #include…
pxr_64
  • 510
  • 1
  • 8
  • 23
0
votes
1 answer

Segmentation fault while printing first element of string array in c

I am scanning lines from a textfile and putting elements into specific arrays, sscanf is working fine and inserting variables into arrays as well BUT printing out first element of string array result in segmentation fault(printing works for first…
Heksan
  • 3
  • 2