Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
178 views

I have this code in C11 (skipping references to pre-declared variables and functions): // [...] char *old_buf = it->buf; shift += it->buf_size; it->buf_size *= ...
user3758232's user avatar
0 votes
3 answers
219 views

I have just encountered a case in this C program: void row_del(int**& a, int& row, int col, int k) { for (int j = 0; j < col; j++) { for (int i = k; i < row - 1; i++) { ...
hacklo's user avatar
  • 17
1 vote
1 answer
180 views

Can you kindly review both code fragments and tell me why shifting the line scanf("%d", (access + csize)); after if statement is solving the issue (see CODE2)? Ideally this line should give ...
0xChaitanya's user avatar
3 votes
4 answers
150 views

I have a small project (ed-like text editor for myself. Just want to edit some config files using it) and I have some problems with it. workspace_file->flc = malloc(sizeof(char *)); ...
Ho1Ai's user avatar
  • 39
1 vote
1 answer
200 views

I have a function which I give a char** input. Inside the function I am calling realloc. I am calling the function multiple times without any issues, but it always crashes at the same point with &...
MVlgr's user avatar
  • 21
0 votes
2 answers
174 views

This is all developed with Visual Stodio 2022 on a Windows 10 platform. I am having some problems getting the library function realloc() to work correctly. I have the function adjustRGBA(), which ...
csharp's user avatar
  • 594
1 vote
1 answer
141 views

I am programming an RP2040 chip using the Pico-Arduino library. In this problem, I am using the Ardunio String class and the Adafruit_NeoPixel class. After setting up some "Strings" and a ...
Scott's user avatar
  • 1,429
-6 votes
1 answer
129 views

I have an array of pointers that I declared like this: struct vallue {has variables but it shouldn't be important atm}; struct array { struct vallue** array_of_pointers_to_structs; int size; }...
Safarov Arthur's user avatar
0 votes
2 answers
162 views

I have a code where I need to delete last element of array. I made this code but I am wondering is there a more optimised way of doing this? My version: void DeleteLast(int** array, int* size) { ...
Safarov Arthur's user avatar
1 vote
0 answers
75 views

My C++ application is using own library for memory management. It defines malloc and free and it is statically linked. My application uses few other 3rd party libraries also. I got a crash in one of ...
sampathA's user avatar
2 votes
1 answer
101 views

I am trying to add memory of my dynamic array using realloc. But in my code, realloc is added extra memory to the array. Suppose initially I want to create array of 5 items than I want to add 3 more ...
user4221591's user avatar
  • 2,236
0 votes
2 answers
132 views

I have wrapped my dynamic memory functions (malloc, calloc, realloc, and free) to track memory usage in my program. I have encountered the following: Calling realloc(NULL, 5) goes directly to my ...
BB_bUrns's user avatar
0 votes
1 answer
142 views

I'm having an issue where, when I run my already compiled program ./main.exe (gcc main.c -o main.exe) through a Makefile, a realloc call fails when the size goes over 40 bytes. However, if I run ./...
iab's user avatar
  • 3
0 votes
1 answer
73 views

How realloc works passed 0 size as argument? from man page: Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc(), or realloc(). Why it needs to be? compile this ...
Force Security's user avatar
2 votes
1 answer
102 views

I have to write a program that is able to take in a file of grades, read them, and then provide some options to be able to edit that file. I decided to write it in C (for the challenge, and to learn ...
fwamingo 273's user avatar
0 votes
3 answers
91 views

Sorry for my bad English. I have an exercise from school. I need to teach my friends to work with pointers in C. So i want to narrate them about a double pointer (type **ptr). I tried to write a code ...
Лев Чекунаев's user avatar
0 votes
1 answer
114 views

I'm a computer science student and one of the questions on a test asked to implement realloc in C using malloc. My teacher said the correct answer would be to get the sizeof of the previous array and ...
PublicEnemy0's user avatar
1 vote
1 answer
114 views

I am trying to write a ThreadPool library for C; mostly for educational purposes, but also perhaps for practical usage later. I have an implementation that "works", in that I can spin up ...
smolloy's user avatar
  • 368
0 votes
2 answers
80 views

As I know, realloc is supposed to make a bigger/smaller allocation and copy the data given to it here. I was making a sprisheet atlas parser and encountered this, then reproduced it with very simple ...
Sirox's user avatar
  • 1
0 votes
2 answers
144 views

I'm writing an application that generates a bunch of n strings (bit)length l and then does a comparison between all possible pairs. I first allocate memory for n strings of length l char* pStr = (char*...
Mori's user avatar
  • 31
0 votes
1 answer
71 views

compiled the following code snippet with command: gcc -g -std=c99 src.c src.c: #include <stdio.h> #include <stdlib.h> void fill(int* arr, int len, int val) { for (int i = 0; i < ...
Abhijeet Mohapatra's user avatar
0 votes
1 answer
85 views

Whenever I try to run this code I've written, it works fine the first time. The second time, the execution hangs up at the end ( it executes everything in the function, but never exits the function ). ...
Tangsten's user avatar
0 votes
0 answers
86 views

Here is the section of code where my program crashes: if (fromNode != toNode) { pthread_mutex_lock(&mtxs[fromNode]); g->out[fromNode]++; if (g->in[toNode].index == g->in[...
XOpt 6's user avatar
  • 11
32 votes
2 answers
1k views

According to the change log of C23, proposal n2464 was voted-in and implemented, making realloc(ptr, 0) explicitly undefined behavior, whereas it was supposedly implementation-defined in previous ...
Lundin's user avatar
  • 220k
0 votes
1 answer
131 views

I have 2 variants of code: 1st: void PrintMem(const int* memarr,const size_t size) { for (size_t index = 0; index < size; ++index) { std::cout << '<'<<(index+1)<<&...
vansergh's user avatar
  • 101
1 vote
0 answers
57 views

In C you can do something like this: int size = 10; int *foo = (int*)calloc(size, sizeof(int)); size = 5; foo = realloc(foo, size * sizeof(int)); So where does the memory for cropped 5 elements go? ...
dikiy_opezdal's user avatar
1 vote
0 answers
55 views

I use some external lib written in C that implement hash table. When hash table size need to grow it uses realloc to double the memory space for keys/values. I familiar with this behavior but others ...
Brave's user avatar
  • 329
0 votes
2 answers
143 views

I have tried solving this problem by googling about calloc() and realloc(). I saw videos about it.I read similar cases in stackoverflow but due to C++ and struct usage I had trouble understanding how ...
Sotiris's user avatar
  • 21
0 votes
1 answer
98 views

I have this simple code snippet as seen below: #include <stdio.h> #include <stdlib.h> int main() { int size; int *a, *a2; size = 5; a = malloc(size * sizeof(int)); if(...
Agent 47's user avatar
-2 votes
1 answer
90 views

I'm encountering an issue while reading an file that contains records with length indicators and fields separated by '|'. In this program, I'm reading information about the quantity and price of a ...
Lucas Froes's user avatar
0 votes
4 answers
135 views

#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { char *s; s = malloc(1024 * sizeof(char)); scanf("%[^\n]", s); ...
chiranjeevi_dk's user avatar
0 votes
1 answer
79 views

void addWorkerToProject(Worker *worker, Project *project) { worker->projects = malloc(sizeof (strlen(project)+1)); worker->projects[worker->projectCount]->name = project->name;...
strtrs's user avatar
  • 1
1 vote
1 answer
94 views

I am trying to develop a linear algebra library from scratch for various matrix operations. I faced a problem while adding a new row to a matrix. I store the matrix using the Column major formula, and ...
MegaRK's user avatar
  • 11
1 vote
1 answer
96 views

Good afternoon everyone! I wrote my implementation of the cat utility in C and ran into some problems. Here's my code: #include <getopt.h> #include <stdio.h> #include <stdlib.h> #...
Алексей Курочкин's user avatar
0 votes
2 answers
382 views

I have some code that was written to be as conservative as possible with memory use, so it does things like use realloc() for building strings a character at a time instead of a one-time fixed-length ...
MeSteve's user avatar
  • 33
0 votes
1 answer
341 views

I have written this code to store a dynamic array of strings on which different operations can be performed. It works correctly when I enter the strings initially and when I add 2 strings, but on the ...
ErrorEliminator's user avatar
1 vote
1 answer
74 views

I'm working on a C program to create an interactive interface for a dynamic array of strings. The program is menu-driven and follows these steps: Asks the user for the initial length of the array. ...
ParthJha17's user avatar
1 vote
2 answers
2k views

Why am I getting a segmentation fault? When I compile with sanitize=address I get a heap-use-after-free which I don't quite understand (the reason for). I get heap-use-after-free on address xyz. Read ...
Aethalides's user avatar
0 votes
1 answer
113 views

I wrote a function to append pointer to an object to array, but realloc can't properly reallocate memory when it's called from a nested function. However, when I'm reallocating memory from function, ...
lian's user avatar
  • 543
2 votes
1 answer
131 views

I tried to implement a dynamic generic array. However, when I tested my code, the result I got was "segmentation fault". I know that this error happens by realloc in a function ...
P1g30n5's user avatar
  • 23
-1 votes
1 answer
97 views

I have a problem in my C program that makes it so that it segfaults on malloc(1). I've spent many hours trying to find out why it segfaults but I just can't figure it out. This portion of my program ...
Adrian F's user avatar
1 vote
2 answers
72 views

I'm trying to use realloc in this program to increase an array's size, using pointer to pointer. But it doesn't end up doing the task: #include <stdio.h> void push(int** data) { *data = (...
Javad's user avatar
  • 13
1 vote
1 answer
144 views

I am very new to C (started 4 days ago, do have a background in Python and Java). I tried to create a dynamic array (python list) to solve advent of code day 4 part 2. The own list and win list works ...
Steven Dang's user avatar
0 votes
2 answers
130 views

I wanted to expand an array dynamically as the user enters the values using below code. #include<stdio.h> #include<stdlib.h> int main(){ int *number=(int *)malloc(sizeof(int)),i=0,*...
Newtron Malayalam's user avatar
1 vote
1 answer
61 views

#include <stdio.h> #include <stdlib.h> int LENGTH = 1; int TOP = -1; void push(char**, char); char pop(char*); char peek(char*); int isEmpty(); int isFull(); void convertToRPN(char*, ...
Nurana's user avatar
  • 15
0 votes
1 answer
49 views

when calling init_model() function I am trying to recursively travel through a tree and append the pointers to the lowest treenodes in an array of treenode pointers. however I am getting segfault when ...
Tomas Whiteley's user avatar
0 votes
0 answers
83 views

I'm developing a custom dynamically scaled array module that aims to minimize the number of realloc calls while maintaining efficient memory usage. The module utilizes a strategy of doubling the ...
Ertugrul's user avatar
  • 175
0 votes
0 answers
49 views

I'm implementing a dynamic unsigned array struct (equivalent to C++ std::vector) and I'm facing some issues when reallocating for push_back. Here is the relevant code: #include <stdio.h> #...
Caio Vinícius's user avatar
0 votes
1 answer
131 views

I'm Tryng to write a code that have to expand the memory of a malloc array of 1 for some cicles of a loop (i need to store the zeros of a function). but after compiling this error occurs: realloc(): ...
Dario Rubriante's user avatar
0 votes
1 answer
180 views

This code is from a problem in HackerRank (Q: Printing Tokens in C). #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char *s = malloc(1024 * sizeof(char))...
Prabash's user avatar
  • 15

1
2 3 4 5
36