我试图用C语言编程,但并不成功.我有一个简单的源代码,我需要匹配多个字母if (char).它显示以下错误消息(在使用gcc的linux终端中):
main.c:在函数`main'中:main.c:16:23:警告:字符常量对于其类型太长[默认启用]
if(firstName [20] =='Vojta'){
源代码:
#include <stdio.h>
int main(int argc, char const *argv[])
{
/* code */
char firstName[20];
char lastName[40];
char password[20];
char confpasswd[20];
int age;
printf("Please write your first and last name:");
scanf("%s%s", firstName, lastName);
printf("%s %s:\n", firstName, lastName);
if (firstName[20] == 'Vojta'){
printf("\ncool\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有这个小程序(我知道有很多错误):
#!/usr/bin/python
import os.path
import sys
filearg = sys.argv[0]
if (filearg == ""):
filearg = input("")
else:
if (os.path.isfile(filearg)):
print "File exist"
else:
print"No file"
print filearg
print "wasn't found"
Run Code Online (Sandbox Code Playgroud)
如果我通过打字开始 python file.py testfile.txt
输出将始终(即使文件不存在):
File exist
Run Code Online (Sandbox Code Playgroud)
如果您不知道我想从这个程序中得到什么,我想打印"文件'文件名'未找到"如果文件不存在,如果它存在我想不打印"文件存在"
有什么想法可以解决吗?谢谢