小编Jus*_*ung的帖子

了解C中的scanf

所以我对编程很新,我在3天前开始使用C语言.我正在创建这个简短的程序来测试自己.这只是一个非常基本的C程序,要求你的名字和姓氏.这是代码:

#include <stdio.h>

int main() 
{

    char first[20];

    char last[20];

    printf("Please enter your first name:");
    scanf("%s",&first);
    printf("\nand Please enter your last name:");
    scanf("%s",&last);
    printf("Greetings fellow %s %s!\n",first,last);
    return(0);
}
Run Code Online (Sandbox Code Playgroud)

但是当我去编译时,我每次都会得到这个错误:

checkname.c:9: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’ checkname.c:11: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’

我知道我可以使用,gets()但显然它很糟糕,我不应该使用它.这段代码有什么问题?我不明白问题是什么.

c scanf

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

简单的c ++输入程序

我尝试制作一个非常小的基本程序来尝试使用不是单个数字或字母的输入.我输入了这段代码,但它不起作用.它启动并工作但是当你输入输入时它会停止程序而不使用if和else if.为什么这不起作用?

int main()
{
    using std::cout;
    using std::cin;
    using std::endl;

    char input[256];

    cout << "Is Life Good?\n";
    cin >> input;

    if (input == "yes") {
    }
    else if (input == "Yes") {
        cout << "Good\n";
    }
    else if (input == "YES") {
        cout << "Good\n";
    }
    else if (input == "no") {
        cout << "Change something\n";
    }
    else if (input == "No") {
        cout << "Change something\n";
    }
    else if (input == "NO") {
        cout << "Change something\n";
    } …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
136
查看次数

标签 统计

c ×1

c++ ×1

scanf ×1