c - 在 Visual Studio 中放置要用作命令行参数的文件的位置

标签 c visual-studio file command-line

我正在使用 Visual Studio 在 C 中创建一个项目,我需要它来读取文件并对文件中的文本进行分析。我必须将文件传递给命令行,但我不知道将文件放在哪里以便读取它。以下是帮助解释其工作原理的主要方法:

int main(int argc, char *argv[]){

FILE * cmdFile;
char * nxtCmd = (char *) malloc(sizeof(char) * STR_LEN);

//Ensure memory allocation for nxtCmd succeeds
if (nxtCmd == NULL){
    puts("Memory failed to allocate for nxtCmd.");
    exit(1);
}

// check if argc is 2
if(argc == MAX_ARGS){}
else{
    puts("Innapropriate number of arguments passed to the program.");
    exit(1);
}

// check that argv[1] can be opened
if ((cmdFile = fopen(argv[1], "r")) == NULL){
    puts("Can't open the command file.");
    exit(1);
}

else{
    puts("Command file has opened successfully.");
}

// if both above are true:
//    start reading from the cmdfile
while ((nxtCmd = nextLine(cmdFile)) != NULL){
    nxtCmd = nextLine(cmdFile);
    printf("next line: %s", nxtCmd);
}
}

如有任何帮助或意见,我们将不胜感激。

最佳答案

任何地方都可以,只需将它传递给命令行上的程序即可:

myprog.exe \path\to\file.txt

关于c - 在 Visual Studio 中放置要用作命令行参数的文件的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333769/

相关文章:

c - 替换 C 数据中的字节

javascript - Typescript Web 音频 API 缺少定义

visual-studio - 哪些 VS.NET 设置会影响 F# 交互式窗口的主题颜色

sql-server - SSRS - 自定义参数布局已从报告中删除

c++ - 为什么要使用 char 数组来存储以二进制模式打开的文件的内容?

c - 文件扫描多行时跳过行

c - 如何打破 openmp for 循环?

c - 从 C 中的 BST 中删除

python - 如何将原始字节作为参数提供给 C 程序

java - 用二维数组java写入txt文件