Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A code that doesn't work on gcc

Tags:

c

gcc

I wrote a calculator program in visual studio. But i need it to run with also DEVC++. But my code doesn't work on gcc compiler. Here is a little part of the code that doesn't work.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>

int main(){

    long double var1 = 0, var2= 0, memory, result;
    char wordInput[50] = { 0 };
    char *endPtr1, *endPtr2;

    printf("Enter an input: ";
    scanf("%[^\n]%*c", wordInput);

    var1 = strtold(wordInput, &endPtr1);
    printf("%.4f", var1);

}

This is the block of code where i get the input and convert it to double and assign to the var1. When i compile it with visual studio it works(it prints the number which is entered) but with devc++ it doesn't (it prints 0.0000). What can i do to fix it?

like image 991
Tolga Şen Avatar asked Dec 08 '25 06:12

Tolga Şen


1 Answers

try this

#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h>

....

    printf("%.4Lf", var1);
like image 165
BLUEPIXY Avatar answered Dec 10 '25 19:12

BLUEPIXY