cosmopolitan
cosmopolitan copied to clipboard
Bug: printf() isn't working as expected
Contact Details
contact me on here
What happened?
hello. found a weird issue with printf, I don't know why this happens, but if I compile my example calculator app, it doesn't print to stdout until you fill out all needed stuff, here's the C code.
#include<stdio.h>
#include<stdlib.h>
int main(){
printf("welcome in calculator.");
char *choice=malloc(sizeof(char));
printf("type in the operator");
scanf("%c",choice);
switch(*choice)
{
case '/':
free(choice);
printf("first number");
int64_t *num1=malloc(sizeof(int64_t));
int64_t *num2=malloc(sizeof(int64_t));
printf("first number");
scanf("%lld",num1);
printf("second number");
scanf("%lld",num2);
int64_t *result=malloc(sizeof(int64_t));
*result =*num1 / *num2;
free(num1);
free(num2);
printf("%lld",*result);
free(result);
break;
case '+':
free(choice);
int64_t *Num1=malloc(sizeof(int64_t));
int64_t *Num2=malloc(sizeof(int64_t));
printf("type in first number");
scanf("%lld",Num1);
printf("second number");
scanf("%lld",Num2);
int64_t *Result=malloc(sizeof(int64_t));
*Result= *Num1+ *Num2;
free(Num1);
free(Num2);
printf("%lld",*Result);
free(Result);
break;
case '*':
free(choice);
int64_t *n1=malloc(sizeof(int64_t));
int64_t *n2=malloc(sizeof(int64_t));
scanf("%lld",n1);
scanf("%lld",n2);
int64_t *res=malloc(sizeof(int64_t));
*res= *n1 * *n2;
free(n1);
free(n2);
printf("%lld",*res);
free(res);
break;
case '-':
free(choice);
int64_t *N1=malloc(sizeof(int64_t));
int64_t *N2=malloc(sizeof(int64_t));
printf("type in the first number");
scanf("%lld",N1);
printf("type in second number");
scanf("%lld",N2);
int64_t *Res=malloc(sizeof(int64_t));
*Res= *N1- *N2;
free(N1);
free(N2);
printf("%lld",*Res);
free(Res);
break;
}
}
Version
cosmocc (GCC) 14.1.0
What operating system are you seeing the problem on?
Mac
Relevant log output
No response