用白色分隔的数字行 space 是 C 中的整数类型吗?
Line of numbers separated with white space is type of integer in C?
我是 C 的新手,已经对它的数据类型感到厌倦了。
#include <stdio.h>
#include <string.h>
int main ()
{
char command[50];
strcpy( command, "ps -x | wc" );
int first = pepen(command);
int two_digit = first;
printf("two = %i, three = %d", two_digit, first);
return(0);
}
我想获得 int first
的前两个数字 88
。
我不知道 int first
等于哪种整数。当我使用 %c
而不是 %d
终端报告我 int first
是整数类型并使用 first[0]
报告它不是对象时。那么 first
的类型是什么
我怎样才能只打印前两位白色,它们之间有 space?
IF(这是一个很大的if):
- 您使用的是类 Unix 系统,并且
- 您 运行 在标准输出上生成数字的命令,
那么你可能可以使用 popen()
和 pclose()
到 运行 命令并读取命令的输出:
#include <stdio.h>
int main(void)
{
char command[] = "echo 82 509 8274";
FILE *fp = popen(command, "r");
if (fp != 0)
{
int first;
if (fscanf(fp, "%d", &first) == 1)
printf("Got %d from the command\n", first);
pclose(fp);
}
return 0;
}
我是 C 的新手,已经对它的数据类型感到厌倦了。
#include <stdio.h>
#include <string.h>
int main ()
{
char command[50];
strcpy( command, "ps -x | wc" );
int first = pepen(command);
int two_digit = first;
printf("two = %i, three = %d", two_digit, first);
return(0);
}
我想获得 int first
的前两个数字 88
。
我不知道 int first
等于哪种整数。当我使用 %c
而不是 %d
终端报告我 int first
是整数类型并使用 first[0]
报告它不是对象时。那么 first
的类型是什么
我怎样才能只打印前两位白色,它们之间有 space?
IF(这是一个很大的if):
- 您使用的是类 Unix 系统,并且
- 您 运行 在标准输出上生成数字的命令,
那么你可能可以使用 popen()
和 pclose()
到 运行 命令并读取命令的输出:
#include <stdio.h>
int main(void)
{
char command[] = "echo 82 509 8274";
FILE *fp = popen(command, "r");
if (fp != 0)
{
int first;
if (fscanf(fp, "%d", &first) == 1)
printf("Got %d from the command\n", first);
pclose(fp);
}
return 0;
}