问题描述
我在 C 代码中遇到了一些问题。问题是我通常无法比较两个字符串并执行进一步的操作。代码(问题出在第 71 行:if (strcmp("/help",choice) == 0) { )
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
char services[][100] = {
"YouTube","Twitter","Facebook","Google","VKontakte","Instagram","CMD","discord","Roblox",};
void servicePrint()
{
size_t serviceLength = sizeof(services) / sizeof(services[0]);
for (int i = 0; i < serviceLength; i++) {
printf("%s - opens %s.\n",services[i],services[i]);
}
}
int main(int argc,char *argv[])
{
int arguments = 0;
if (argc > 1)
arguments = 1;
char command[100];
char choice[100];
printf("hey! What do you want to open? (/help - for help) ");
fgets(choice,sizeof(choice),stdin);
puts("\n");
char helpCmd[] = "/help";
if (strcmp(choice,"/help\n") == 0) {
servicePrint();
} else {
printf("Please enter a valid command! (/help - for help)\n");
fprintf(stderr,"%s","Wrong command entered!");
return 2;
}
strcpy(command,"");
system(command);
return 0;
}
我已经尝试了很多次,改变了 args 的位置等。但是还是没有结果。 帮助将不胜感激!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)