I'm struggling with realloc...
strucType mkBggr (structType x, char ch) {
x = realloc(x, 100);
printf("%d", sizeof(x));
}
I'm thinking this should print out the value 100, but it prints 8.
It obviously has something to do with pointers,…
My code (or the example from the book) seems to not work. I know it's the realloc function causing this, since I will allocate some memory to a set amount at the beginning. If I surpass the original amount I allocated, I will realloc() to increase…
#include
#include
#define ALFA 4
int simVarDiscr(int* nr, int l, int nrm) {
int k = 0, i = 1;
double p, q;
q = (double)ALFA / (ALFA + l - 1);
p = (double)nr[1] / (ALFA + l - 1);
double F = p;
double u =…
I have a problem with reallocating an array. I want to save inputs to a string array and realloc it with every new entry.
Heres my function:
char** history=0;
int historycounter=0;
void saveHistory(char* input){
…
I have to write a program that will read text from a file, break it up into a struct, validate the sections to a certain criteria, then produce two new files; one with the clean data and one with the errors. So far i am up to the stage of breaking…
I have an array used to represent a generic stack.
struct Stack {
int size;
int type;
int capacity;
void **data; // An array of generic data.
};
Stack *new_stack(int type) {
Stack *tmp = malloc(sizeof(Stack));
assert(tmp !=…
I'm using the poll function. The library has a structure as so:
struct pollfd{
int fd;
short events;
short revents;
}
Now, in my code I have an array of these events and I need to be able to realloc and give more memory space for more…
I'm using realloc to increase the amount of memory for an array of structs and it doesn't seem to be increasing at all. I've read all of the posts relating to this and I can't figure out what I'm doing wrong. Here is my code:
struct fileInfo…
currently working on some computer science exercises, when I ran into a weird issue.
The idea of the exercise is to create and work on a graph using first dynamic matrices (no issues there) and later an array of linked lists.
The exercise asks to…
So, I was doing this exercise:
Write a C function void occurrences(char* s, char c, char*** occp,
int* n) that, given a string s and a char c, counts the number of
occurrences of char c in the string s, returns that number in n and returns in…
I have trouble reducing the size of dynamically created array. Here's what my main function looks like:
int main(void) {
// Intialize big array
int * a = (int *)malloc(10*sizeof(int));
assert(a);
// Fill it with squares
for (int…
I'm trying to read ints from stdin, but i don't know the length. I tried this but I have no idea why it doesn't work
#include
#include
int main()
{
int *arr = (int *) malloc(sizeof(int));
int sizeCounter = 0;
int…
I'm trying to copy an array of integers in a dynamically allocated array. At first it has size 1 and with every element I want to increase it's size by one.
Here's the code:
#include
#include
int main()
{
int *nr,i;
…
I know this use-case might sound a bit strange, but I need to understand if it is possible to do something similar to this.
This is my code, and it causes crash on Aborted (core dumped):
char *my_str = "Hello World";
my_str = realloc(my_str,…
I am trying to write a function that will add a set of data (first name, last name, score) into 3 different dynamic arrays (one 2d char array for the first name, one 2d char array for the the last name, and a float array for the score). Here is my…