hi.
my ask is this:
when i alloc memory in my code with function malloc of library <stdlib.h>
and i going use him...this not work...look my code testing malloc:
if anyone know, please answerme.Code:#include<stdio.h> #include<stdlib.h> int main(){ int *p, num; char *entrada; p = (int *)malloc(sizeof(int)); printf("\nquantos caracters deseja entrar? "); scanf("%d",&num); entrada = (char *)malloc(sizeof(char)*num); if (p == NULL) { printf("ERRO: Sem memoria!\n"); return 1; } printf("Insira um valor:"); scanf("%d",p); printf("Digite uma string:"); fgets(entrada,num,stdin); printf("Voce Entrou com o valor %d\n",*p); printf("Voce digitou a string %s\n",entrada); free(p); free(entrada); return(0); }
One kiss in your asses.