我在Windows上使用最新的gcc和Netbeans.为什么不起作用long double?是printf符%lf错了吗?
码:
#include <stdio.h>
int main(void)
{
float aboat = 32000.0;
double abet = 5.32e-5;
long double dip = 5.32e-5;
printf("%f can be written %e\n", aboat, aboat);
printf("%f can be written %e\n", abet, abet);
printf("%lf can be written %le\n", dip, dip);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
32000.000000 can be written 3.200000e+004
0.000053 can be written 5.320000e-005
-1950228512509697500000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000.000000
can be written 2.725000e+002
Press [Enter] to close the terminal ...
Run Code Online (Sandbox Code Playgroud) 如何打印(带printf)复数?例如,如果我有这个代码:
#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex dc1 = 3 + 2*I;
double complex dc2 = 4 + 5*I;
double complex result;
result = dc1 + dc2;
printf(" ??? \n", result);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
..我应该使用什么转换说明符(或其他东西)"???"
当我点击项目属性时,我可以设置Warning level(More Warnings)和Command Line -> Additional Options(-std=c99).但我希望我的所有C项目默认都有这种选项,而不是每次创建新项目时都手动设置它们.

#include <stdio.h>
#include <inttypes.h>
int main(void)
{
int8_t int8;
int16_t int16;
int32_t int32;
int64_t int64;
uint8_t uint8;
uint16_t uint16;
uint32_t uint32;
uint64_t uint64;
scanf("%"SCNd8"%"SCNd16"%"SCNd32"%"SCNd64"%"SCNu8"%"SCNu16"%"SCNu32"%"SCNu64,
&int8, &int16, &int32, &int64, &uint8, &uint16, &uint32, &uint64);
printf("%"PRId8"\n%"PRId16"\n%"PRId32"\n%"PRId64"\n%"PRIu8"\n%"PRIu16"\n%"PRIu32"\n%"PRIu64"\n",
int8, int16, int32, int64, uint8, uint16, uint32, uint64);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我无法使用最新的gcc + MinGW + Netbeans + Windows编译此代码.Netbeans说"无法解析标识符SCNd8和SCNu8".我在gcc手册页上找不到SCNd8和SCNu8的任何参考,尽管http://linux.die.net/include/inttypes.h定义了它们.使用PRId8或PRIu8时,我没有收到语法错误.
MinGW inttypes.h(缺少SCNd8和SCNu8)(示例代码)
#define PRIXFAST64 "I64X"
#define PRIXMAX "I64X"
#define PRIXPTR "X"
/*
* fscanf macros for signed int types
* NOTE: if 32-bit int is used for …Run Code Online (Sandbox Code Playgroud) 我在同一文件夹中有程序 proba2.exe 和文件 text.txt,当我在项目属性中设置命令行参数时,它无法打开文件,但是当我从命令提示符运行程序时,它工作正常。
/* count.c -- using standard I/O */
#include <stdio.h>
#include <stdlib.h> // ANSI C exit() prototype
int main(int argc, char *argv[])
{
int ch; // place to store each character as read
FILE *fp; // "file pointer"
long count = 0;
if (argc != 2)
{
printf("Usage: %s filename\n", argv[0]);
exit(1);
}
if ((fp = fopen(argv[1], "r")) == NULL)
{
printf("Can't open %s\n", argv[1]);
exit(1);
}
while ((ch = getc(fp)) != EOF)
{
putc(ch,stdout); // same …Run Code Online (Sandbox Code Playgroud) 此scanf应始终返回true,直到我输入无数字输入,但此scanf从不执行循环.为什么?
样本输入:
10.0 5.0
Press [Enter] to close the terminal ...
Run Code Online (Sandbox Code Playgroud)
码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
float a, b;
while ( scanf("%f %f", &a, &b) == 1 )
{
printf("%f\n", (a - b) / (a * b));
}
return (EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)