Questions tagged as 'malloc'

1
answer

How does malloc organize memory?

When I allocate memory with malloc() , are the addresses equal to a vector? Or are they scattered in the memory of the PC? I want to create a list of structs , to do this, I have to have several structs in case, can I do th...
asked by 10.11.2017 / 18:07
1
answer

Something simpler than this to allocate a typed text dynamically?

// FUNCAO // char *nome(char text[20]) { char *n; int n2; int n3 = 0; printf("%s\n",text); while((n2 = getchar()) != '\n' && n2 != EOF) { if(n3 < 1) { n = (char*) malloc(sizeof(char));/...
asked by 19.06.2017 / 03:20
1
answer

Malloc does not work in C code

When trying to compile the code I get the following error messages: #include<stdio.h>#include<stdlib.h>#defineOK0voidpreencherVetor(int*vetor[],inttamanho){intindice;for(indice=0;indice<tamanho;indice++){printf("Entre com o va...
asked by 16.05.2017 / 22:07
1
answer

dynamic reallocation - struct array

I need to do an exercise in which the code allocates memory as needed, but I need to relocate an array of structs, but I ended up locking in that part. My Struct is: typedef struct{ char nome[100]; char endereco[100]; int numero...
asked by 23.05.2018 / 00:01
0
answers

vector / dynamic queue segmentation failure

Hello, the following code is missing targeting. Basically I can not scan this entry: ISCOD4 2 3 10 20 1 10.1.1.151 10.1.2.151 10240 1 2 10.1.1.153 10.1.4.152 12288 2 3 10.1.1.156 10.1.4.153 14336 3 4 10.1.1.156 10.1.2.150 2048 1 5 10.1.1.157 1...
asked by 04.11.2017 / 00:49
1
answer

Malloc function error: sysmalloc: Assertion failed in C

I'm implementing a Red Black Tree in C, and when I go to allocate memory for the second node, it gives the error:    sysmalloc: Assertion [...] failed. Aborted (core dumped) I have already researched and imagined that when I allocate memo...
asked by 07.11.2018 / 04:27
1
answer

insert names neatly into a list, I'm not aware of this

// insert function ai; then only do this with the first 3 names, the others she does not order Aluno *cad(Aluno *aluno) { Aluno *aux; while(1) { aux = aluno; if(aux->prox == NULL) { Aluno *criar = novo(); i...
asked by 23.05.2018 / 21:39
1
answer

When actually using malloc () and / or calloc ()?

My doubt is that you are learning from banal examples (as I see it), as in: int *ptr; ptr = malloc(sizeof(int)); I find it useless to allocate a space from an integer to an integer pointer, does it not do it alone anymore? When do...
asked by 04.12.2018 / 01:30
1
answer

Print available memory in C [closed]

How to know how much memory is available before doing malloc ? I would like to print the memory value that is still available to be able to be allocated, the code must run under Windows and Linux . On a computer I think that this...
asked by 27.08.2018 / 13:56
1
answer

Malloc in a string, based on the size of a FILE

int main(void) { FILE *p = fopen("matriz.txt","r+"); char *arquivo; arquivo=(char*)malloc(sizeof(p+1)*sizeof(char)); while (fgets(arquivo,sizeof(arquivo),p)) { printf(" %s",arquivo ); } }//END the matrix cont...
asked by 13.12.2018 / 14:53