小编gam*_*boy的帖子

printf和long double

我在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)

c printf gcc long-double

52
推荐指数
6
解决办法
23万
查看次数

C复数和printf

如何打印(带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)

..我应该使用什么转换说明符(或其他东西)"???"

c printf complex-numbers

46
推荐指数
2
解决办法
3万
查看次数

GCC的NetBeans设置

当我点击项目属性时,我可以设置Warning level(More Warnings)和Command Line -> Additional Options(-std=c99).但我希望我的所有C项目默认都有这种选项,而不是每次创建新项目时都手动设置它们.

截图

c gcc netbeans mingw makefile

12
推荐指数
2
解决办法
6177
查看次数

gcc(windows + MinGW)是否在inttypes.h中定义了SCNd8,SCNu8?

#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)

c gcc mingw c99

5
推荐指数
2
解决办法
5328
查看次数

C程序无法打开文件

我在同一文件夹中有程序 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)

c netbeans file

1
推荐指数
1
解决办法
3万
查看次数

为什么这个scanf返回false?

此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)

c c++

0
推荐指数
1
解决办法
476
查看次数

标签 统计

c ×6

gcc ×3

mingw ×2

netbeans ×2

printf ×2

c++ ×1

c99 ×1

complex-numbers ×1

file ×1

long-double ×1

makefile ×1