传递 'fgets' 的参数 1 使指针来自整数而不进行强制转换

Passing argument 1 of 'fgets' makes pointer from integer without a cast

我 运行 这段代码出现以下错误,我做了一些研究,但我没有真正得到答案我希望你们中的任何人能给我一点帮助。我是编程新手,如果我遗漏了一些太明显的东西,请原谅我。

[Warning] passing argument 1 of 'fgets' makes pointer from integer without a cast

int main(int argc, char *argv[]) {
 char *t,*s;
 char first, second;
 int x;

 printf("Give the first string: ");
 fgets(first,sizeof(char),stdin);
 printf("Give the second string: ");
 fgets(second,sizeof(char),stdin);
}

当我在我的 "first" 和 "second" 变量中添加一个“&”时,它会编译,但是当我 运行 它时,我没有得到我从键盘输入的字符串.

如何编译?

fgets 期望 char* 指向缓冲区作为第一个参数

int main(int argc, char *argv[]) {
    char first[80], second[80];

    printf("Give the first string: ");
    fgets(first, sizeof(char), stdin);
    printf("Give the second string: ");
    fgets(second, sizeof(char), stdin);
}

fgets表示"get a string from a file",你需要一个char数组来保存一个字符串。

你应该把first和second变成指针分配space填入

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

int flen = 256;
int slen = 256;
 char* first = malloc(flen); //allocate enough space to handle verbose typists :)
 char* second = malloc(slen);
 int x;

 printf("%s\n","Give the first string: ");
 fgets(first,flen,stdin);

 printf("%s\n","Give the second string: ");
 fgets(second,slen,stdin);

//do something with first and second.

//free memory you allocated
free(first);
free(second);
};