小编Acr*_*ear的帖子

在C中写入stdout是什么意思?

写入"stdout"的程序是否写入文件?屏幕?我不明白写入stdout意味着什么.

c unix stdout

33
推荐指数
4
解决办法
15万
查看次数

将optarg分配给C中的int

我试图将一个optarg值赋给一个int,但编译器给了我以下警告:

warning: assignment makes integer from pointer without a cast [enabled by default]
Run Code Online (Sandbox Code Playgroud)

我已经尝试在分配之前将optarg转换为int

n = (int) optarg;
Run Code Online (Sandbox Code Playgroud)

但仍然收到警告:

warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
Run Code Online (Sandbox Code Playgroud)

在我可以简单地将optarg分配给一个整数然后打印它(现在)之前,我不确定需要做什么.

int main (int argc, char *argv[])
{
  char c;
  int n;

  while ((c = getopt(argc, argv, "m:")) != -1) {
    switch (c) {
    case 'm':
      n = optarg;
      break;
    }
  }

  printf("%d\n", n);

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c unix int casting

4
推荐指数
2
解决办法
7951
查看次数

在 C 中使用 math.h sqrt 函数

阅读 math.h 的文档,似乎我所要做的就是包含 math.h,并使用包含的数学函数,例如 sqrt。问题是当我尝试在程序中使用 sqrt 时出现以下错误。我尝试了 math.sqrt,但这也不起作用。知道我做错了什么吗?

undefined reference to `sqrt'
Run Code Online (Sandbox Code Playgroud)

...

#include <stdio.h>
#include <math.h>

int main (int argc, char *argv[])
{
  int a, b;

  a = 1;
  b = 5;

  if (a < sqrt (b))
    printf("1 < sqrt(5)");

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c unix math sqrt

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

在C中通过引用无效

我无法通过引用获得简单的传递,以我期望的方式工作.拳头关闭,当我编译时,我得到以下警告:

warning: value computed is not used [-Wunused-value]
Run Code Online (Sandbox Code Playgroud)

其次,我希望在程序结束时打印2,而不是1.

$ ./testAdd
1
Run Code Online (Sandbox Code Playgroud)

这是简单的代码:

#include <stdio.h>

void addone(int *j) {
  *j++;
}

int main(int argc, char *argv[])
{
  int i = 1;

  addone(&i);

  printf("%d\n", i);

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这里出了什么问题?

c operator-precedence

2
推荐指数
1
解决办法
348
查看次数

标签 统计

c ×4

unix ×3

casting ×1

int ×1

math ×1

operator-precedence ×1

sqrt ×1

stdout ×1