我有一个头文件假设abc.h,其中我有函数声明为:
static int function1();
Run Code Online (Sandbox Code Playgroud)
我已将此头文件包含在abc.c中并定义了该函数并使用了它.
static int function1()
{
< function definition>
}
Run Code Online (Sandbox Code Playgroud)
编译后我收到警告:
warning: function1 declared static but never defined
Run Code Online (Sandbox Code Playgroud)
如何在不删除静电的情况下删除警告.谢谢.
例如,我想在c中打印一个最多2位小数的值,而不是将其四舍五入.
喜欢:
a = 91.827345;
printf("%.2f", a);
Run Code Online (Sandbox Code Playgroud)
将打印91.83,但我希望输出91.82只是.怎么做?
#include <stdio.h>
typedef struct
{
int as;
int bs;
int cs;
}asd_t;
typedef struct
{
asd_t asd[10];
}asd_field_t;
typedef struct
{
int a;
int b;
asd_field_t asd_field[10];
}abc_t;
int main()
{
abc_t abc ={0,1,{0}};
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我试图初始化结构abc_t.将上面的代码编译为:
gcc -Wall sample.c
Run Code Online (Sandbox Code Playgroud)
给我:
sample.c: In function 'main':
sample.c:26: warning: missing braces around initializer
sample.c:26: warning: (near initialization for 'abc.asd_field[0].asd')
Run Code Online (Sandbox Code Playgroud)
我该如何避免这种警告?
我想在 shell 脚本中解析以下字符串。
VERSION=2.6.32.54-0.11.def
Run Code Online (Sandbox Code Playgroud)
这里我想得到两个值。
first = 263254
second = 11
Run Code Online (Sandbox Code Playgroud)
我使用以下方法来获取第一个值:
first=`expr substr $VERSION 1 9| sed "s/\.//g" |sed "s/\-//g"`
Run Code Online (Sandbox Code Playgroud)
得到第二个:
second=`expr substr $VERSION 10 6| sed "s/\.//g" |sed "s/\-//g"`
Run Code Online (Sandbox Code Playgroud)
使用上面的代码输出是:
first=263254
second=11
Run Code Online (Sandbox Code Playgroud)
如果版本更改为:结果将不一致:
VERSION=2.6.32.54-0.1.def
Run Code Online (Sandbox Code Playgroud)
这里第二个值将变成 1d,但我希望它只给出 1 的输出。
如何直接解析“-”之后和“.d”之前的数字?