如何为c中的if语句提供数组输入?

问题描述 投票:0回答:3
# include <stdio.h>


void danidev(void){
 printf("Dani is a YouTuber and an indie game developer and an fps game developer having his game published in play store he is 22 years old and goes to a university");
}

void brackeys(void){
    printf("brackeys is a YouTuber and an indie game developer and also an fps game developer having most of his games published in itch.io and has a team which works on game development");
}

void blackthornprod(void){
    printf("  they are two brothers who create video games and teach others how to do the same over on Youtube and Udemy ! they are passionate in sharing their knowledge and game creation journey with other aspiring game developers.");
}

void jabrils(void){
 printf("jabrils is a ai programmer and also a machine learning pro coder and also a game developer he has made a lot of ai and has saved millions of people from their tough times");
}

void codingbullet(void){
 printf("coding bullet is a multi intelligent ai developer and also a master in machine learning also he owns a youtube channel with 2.06 million subscribers");
}

int main(){

 printf("HERE IS THE INFORMATION OF FAMOUS CODING YOUTUBERS(PLS TYPE THE FOLLWOING YOUTUBERS NAME): ");
 char b;
 scanf("%c",&b);
 if(b=='danidev'){
 danidev(); 
 }
 else if(b=='brackeys'){
 brackeys();
 }
 else if(b=='blackthornprod'){
 blackthornprod();
 }
 else if(b=='jabrils'){
 jabrils();
 }
 else if(b=='codingbullet'){
 codingbullet();
 }
 else{
 printf(" i dont know what you are taking about");
 }

return 0;
}

当输入YouTubers名称(全名)作为输入时,我遇到了一个问题,即常量太长且无法提供正确的结果,并且它指出常量字符对于其类型而言太长了] >

#include void danidev(void){printf(“ Dani是YouTuber,是独立游戏开发者,也是fps游戏开发者,他的游戏发布在游戏商店中,他今年22岁,前往...

c arrays if-statement input scanf
3个回答
1
投票

您需要为输入分配更多空间。类型char仅保留一个字符。您需要一个char的数组。可以这样声明:

char b[30];

0
投票

存在一些错误,包括字符串比较,字符串定义和char / char数组变量。有时看起来像JS,但要注意较大的差异。除此之外,我在编写此答案时还看到了另一个答案,我想补充一下scanf中数组的长度,以免在运行时引发缓冲区溢出错误。


0
投票

您不能使用相等运算符(==)直接比较字符串。使用strcmp()来比较两个字符串,而不是等于运算符。

© www.soinside.com 2019 - 2024. All rights reserved.