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

Deleting string from array of strings (C)

I have an array of pointers (char**) which contain some strings. The array ends with an empty string ('\0'). I am supposed to search for a specific word in that array of strings and delete the whole line (ofc using realloc and shortening the array…
Muli Yulzary
  • 2,559
  • 3
  • 21
  • 39
0
votes
1 answer

How do I properly assign pointers in string array in C?

I struggle with pointers in C. I need to put first element of each line into an array. Important parts : char shipname[10]; char **shipTable = NULL; while ( fgets( line,100,myfile) != NULL ) { sscanf(line, "%s %lf %lf %lf %lf", shipname,…
Heksan
  • 3
  • 2
0
votes
2 answers

C - matrix realloc and uninicialized values

I have have matrix that is dynamically allocated depending on the input. One line of input is one row in the matrix. Allocation ends with the EOF. The problem is, if I enter more than one row, valgrind show this. I really dont know what is wrong.…
0
votes
1 answer

Realloc: invalid next size in dynamic vector of structs

I'm trying to make this code work, but I cannot see why it crashes. It is supposed to read data from a file, and put it sorted (insertion sort) in a vector. proc is a vector of Process_t, proc.name is a char[10], proc[0] is inserted before (hard…
markmb
  • 852
  • 4
  • 12
  • 32
0
votes
1 answer

realloc: glibc error doesn't run

I'm having an unfixable problem at realloc statement in main. Please help me: I'm trying to make a file into a vector of lines. error: * glibc detected ./a.out: realloc(): invalid next size: 0x085d9018 ** ? thanks. #include #include…
John
  • 1
  • 3
0
votes
3 answers

Dynamically created C string

I'm trying to get an expression from the user and put it in a dynamically created string. Here's the code: char *get_exp() { char *exp, *tmp = NULL; size_t size = 0; char c; scanf("%c", &c); while (c != EOF && c != '\n') { …
0
votes
1 answer

C - Creating Sub Function To realloc Array Size

I'm having an issue with pointers. I've read through 30+ posts on this subject and none match my setup. Here's what I'm trying to do: void doSomething(myStruct **myList) { resizeMyList(myList,5); myList[0] = '42'; myList[1] = '43'; //…
Mark Löwe
  • 572
  • 1
  • 10
  • 24
0
votes
1 answer

strange behaviour in output

I have a problem with my program to get it run correctly. here is the code: #include #include // for EXIT_SUCCESS and EXIT_FAILURE #include #include void ReadFile(FILE* file) { unsigned lines = 0; …
xlw12
  • 761
  • 1
  • 7
  • 16
0
votes
2 answers

C: SEGFAULT with realloc on char **

Another one in my series of problems with this code. I have below function which is comparing arg with every string in the array of strings reference : char compare(char *arg) { int iter=0; char retchar='0'; while(iter <…
Diwakar Sharma
  • 415
  • 1
  • 9
  • 26
0
votes
1 answer

C: Weird behavior after calling realloc() when using fgets() to store strings in a dynamic buffer

The following code loads in a text file called gasses.txt that has 16 terms, each on its own line, and stores these terms one at a time in the buffer search_terms. #define MAX_LINE_LEN 40 FILE *dict_fp; int term_len; int j; size_t…
Tyler
  • 2,579
  • 2
  • 22
  • 32
0
votes
3 answers

C - dynamical allocation/rellocation inside the function

I have written this function in C (function should receive a char*, allocate space necessary, and insert character given a pointer to the index of character behind the pointer) void add_to_str(char *character, char ** string, int* index) { //we…
Smarty77
  • 1,208
  • 3
  • 15
  • 30
0
votes
1 answer

glibc detected realloc(): invalid next size

#include #include #define SIZE 5 struct CircularQueue{ int front,rear; int capacity; int *data; }; typedef struct CircularQueue * Q; // create queue Q createQueue(int size) { Q q; q = malloc(sizeof(Q)); if(!q) …
user1587676
  • 1
  • 1
  • 1
0
votes
1 answer

realloc struct of array inside function

I have made a library program to store movies in and using dynamic memory allocation for my struct array without success. Adding the first record (movie) works fine, but after the second the values are just messed up characters. There is not really…
Zn3
  • 39
  • 2
  • 3
  • 7
0
votes
1 answer

Reverse string realloc(): invalid next size

I have created this small program to reverse a sentence. So given: a b c d It will give: d c b a This works fine, until I add an extra letter. If I try "a b c d e" it will fail at the last one with the error realloc(): invalid next size:…
AntonioCS
  • 8,335
  • 18
  • 63
  • 92
0
votes
2 answers

Second string corrupt after multiple realloc calls

I was writing a function that allow someone to expand an array of char*, and while doing some test I noticed that when I put more than 3 elements, the second one become something corrupted. This is the function itself: void…
EnryFan
  • 422
  • 3
  • 15