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…
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)…
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…
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…
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,…
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…
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 =…
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…
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…
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…
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…
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…
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…
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:…
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…