EXPLANATION
I'm studying dynamic memory allocation and made a simple program to solve the following situation:
The client wants to make registrations of a certain number of employees and wishes to consult immediately. The program registers the employees using a (Individual) Code and Name provided by the user (client).
main.c
#include <stdio.h>
#include <stdlib.h>
#include "cadastro.h"
#ifdef _WIN32 /*define o comando de limpar a tela com base no SO.*/
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif
int main() {
int qtd_prof, tam_nome, cod;
int stop=0;
char continue_signal;
Profissao *profissao;
system(CLEAR);
printf("Qual o número de profissoes a serem cadastradas?\n");
printf("Insira o valor:\n");
scanf("%d", &qtd_prof);
setbuf(stdin, NULL);
profissao = (Profissao *) malloc(qtd_prof * sizeof(Profissao));
for(int i=0; i<qtd_prof; i++) {
system(CLEAR);
printf("Qual o tamanho do %dº nome?\n", i+1);
printf("Insira o valor:\n");
scanf("%d", &tam_nome);
setbuf(stdin, NULL);
profissao[i].codigo = (int *) malloc(sizeof(int));
profissao[i].nome = (char *) malloc(tam_nome*sizeof(char));
printf("======================================\n");
printf("Qual o codigo do %dº cadastro:\n", i+1);
scanf("%d", &(*profissao[i].codigo));
setbuf(stdin, NULL);
printf("======================================\n");
printf("Qual o nome do %dº cadastro: (MAX: %d)\n", i+1, tam_nome);
scanf("%[^\n]s", profissao[i].nome);
setbuf(stdin, NULL);
/* if(feof(aux)) { //A ideia dessa parte era averiguar a qtd de bytes inseridos.
flag=1;
printf("ERRO! Falha ao tentar gravar o nome.\n");
getchar();
break;
} */
}
printf("======================================\n");
printf("Nomes gravados com sucesso!\n");
printf("Pressione ENTER para continuar!\n");
getchar();
while (!stop) {
system(CLEAR);
printf("Insira o codigo para consulta:\n");
scanf("%d", &cod);
setbuf(stdin, NULL);
for (int i = 0; i < qtd_prof; ++i) {
if(cod == *profissao[i].codigo) {
printf("-----------------------------\n");
printf("Nome: %s\n", profissao[i].nome);
}
}
do {
printf("======================================\n");
printf("Deseja fazer uma nova consulta? (S/N)\n");
scanf("%c", &continue_signal);
setbuf(stdin, NULL);
if (continue_signal == 'S') {
stop = 0;
} else if (continue_signal == 'N') {
stop = 1;
printf("O programa será finalizado!\n");
}
}while (continue_signal != 'S' && continue_signal != 'N');
}
for(int i=0; i<qtd_prof; i++) {
free(profissao[i].codigo);
free(profissao[i].nome);
free(profissao);
}
return 0;
}
cadastro.h
#ifndef CADASTRO_H
#define CADASTRO_H
typedef struct{
int *codigo;
char *nome;
} Profissao;
#endif //CADASTRO_H
Initially, you only have the struct Profession , which has the structuring of each employee's registry that will be implemented by main.c .
PROBLEM
The point is that the code compiles and runs perfectly using gcc (linux). But when I try to compile from within the CLion (JetBrains IDE) I run into the following problem:
Thecodedoesnotevenshowthefirstprintfontheterminal.
CLion has detected GDB, CMake, and Valgrind correctly, and the dependencies are all installed.
I'm posting here, in StackOverflow , looking for someone who has been through the same situation and can help me.