首先,我不得不说我是 C 编程新手。我要做的是编写一个程序,该程序接受参数输入并将其转换为整数,然后返回其值。我的代码如下所示:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int fromArgv = NULL; /* holds value from argv[1] */
fromArgv = atoi (argv[1]); /* convert argv[1] to int */
/* if incorrect no. of arguments entered */
if (argc != 2) {
fprintf (stderr, "error: wrong number of arguments\n");
exit (EXIT_FAILURE);
}
return fromArgv;
}
尝试编译时出现以下错误:
ex1.c: In function ‘main’:
ex1.c:6:18: error: initialization makes integer from pointer without a cast [-Werror]
cc1: all warnings being treated as errors