我是Perl的新手,我正在编写一个程序,我想强制用户输入一个单词.如果用户输入空字符串,则程序应退出.
这是我到目前为止:
print "Enter a word to look up: ";
chomp ($usrword = <STDIN>);
Run Code Online (Sandbox Code Playgroud) C 编程的新手。我正在编写一个程序,我想提示用户输入要打开以供阅读的文件的名称。在我下面显示的代码中,如果它没有打开或文件不存在,我想抛出一个错误,但是当我运行它时,我的代码爆炸了,我必须关闭程序(DOS)
/*ask user for the name of the file*/
printf("enter file name: ");
gets(fname);
//Opens the file from where the text will be read.
fp=fopen(fname, "r");
//Checks if the file us unable to be opened, then it shows the error message
if (fp == NULL)
{
printf("\nError, Unable to open the file for reading\n");
}
Run Code Online (Sandbox Code Playgroud)
// 您可以通过创建 name.txt 文件来测试这一点。如果您需要其他信息,请告诉我。