我正在使用xcode在C中完成学校项目。任务是创建一个命令行应用程序,用于检查单词在文本文件中出现的次数和次数。到目前为止,我刚刚创建了代码的第一步,我已经将第一个争论论点设置为" hej"即使我还没有使用这个词,并且由于没有输入第一个文件名因此为NULL,我已将其设置为名为" hej.txt"的现有文件,以便将我的代码测试为我去。
这一点之前有用:
#include "stdio.h"
#include "string.h"
struct fileSearch
{
char *inFile;
char *outFile;
char *searchWord;
};
int main(int argc, char *argv[])
{
int index = 0;
struct fileSearch f;
f.searchWord = argv[1];
FILE *searchFile;
//For-loop to assign filenames
for(index = 0; index < argc ; ++index)
{
if((strcmp(argv[index], "-i") == 0) && argv[index] != NULL && strcmp(argv[index + 1], "-o") != 0)
{
f.inFile = argv[index + 1];
}
if((strcmp(argv[index], "-o") == 0) && argv[index] != NULL && strcmp(argv[index + 1], "-c") != 0)
{
f.outFile = argv[index + 1];
}
}
if (f.searchWord == NULL)
{
printf("You didnt enter a search word");
}
if (f.inFile == NULL)
{
f.inFile = "hej.txt";
}
if (f.outFile == NULL)
{
f.outFile = "stdout.txt";
}
printf("%s & %s & %s", f.searchWord, f.inFile, f.outFile);
return 0;
}
然后打印出搜索词,输入文件名和输出文件名。
然后我添加了代码的下一步,它将打开文本文件&#34; hej.txt&#34;然后读取字符串并打印出来。
#include "stdio.h"
#include "string.h"
struct fileSearch
{
char *inFile;
char *outFile;
char *searchWord;
};
int main(int argc, char *argv[])
{
int index = 0;
struct fileSearch f;
f.searchWord = argv[1];
FILE *searchFile;
//For-loop to assign filenames
for(index = 0; index < argc ; ++index)
{
if((strcmp(argv[index], "-i") == 0) && argv[index] != NULL && strcmp(argv[index + 1], "-o") != 0)
{
f.inFile = argv[index + 1];
}
if((strcmp(argv[index], "-o") == 0) && argv[index] != NULL && strcmp(argv[index + 1], "-c") != 0)
{
f.outFile = argv[index + 1];
}
}
if (f.searchWord == NULL)
{
printf("You didnt enter a search word");
}
if (f.inFile == NULL)
{
f.inFile = "hej.txt";
}
if (f.outFile == NULL)
{
f.outFile = "stdout.txt";
}
printf("%s & %s & %s", f.searchWord, f.inFile, f.outFile);
//Open file and read
char str[60];
searchFile = fopen(f.inFile, "r");
if(searchFile = fopen(f.inFile, "r") == NULL)
{
printf("Error: There is no file with that name.");
return -1;
}
if(searchFile == NULL)
{
printf("The file is empty");
return -1;
}
while(fgets(str, 60, searchFile) != NULL)
{
puts(str);
}
fclose(searchFile);
return 0;
}
但是现在它成功构建了代码但是当我尝试运行它时,我收到此错误消息:
&#34;错误:可执行文件不存在:&#39; / Users / Slattegard / Library / Developer / Xcode / DerivedData / Coursework-chwsqczjjgxcyegnxgysiaigslvq / Build / Products / Debug / Coursework&#39; 错误:无法启动&#39; / Users / Slattegard / Library / Developer / Xcode / DerivedData / Coursework-chwsqczjjgxcyegnxgysiaigslvq / Build / Products / Debug / Coursework&#39;&#34;
并且问题导航器给了我这条消息:
&#34;检查依赖项 警告:没有处理文件的规则&#39; /Users/Slattegard/Documents/Coursework/Coursework/Find.c'类型为sourcecode.c,用于体系结构x86_64&#34;
任何人都知道我哪里出错了?