c - 查找 C 中的段错误

标签 c segmentation-fault

我已经评论了所有我认为给我带来错误的代码,但我仍然得到它。这是我的代码:

int main(int argc, char **argv) {
    // argc is the number of command line arguments, in our case there are two
    // argv is an array of pointers, a[0] is the program name, a[1] will be sourcewav
    // and a[2] should be destwav
    FILE * source_file;
    FILE * destination_file = fopen(argv[2], "w") ;      // create destwav file

    if (argc != 3) {
        printf("Usage: requires two parameters: sourcewav and destwav");
        exit(1);

    }
    //source_file = fopen(argv[1], "r+");
    if (!source_file) {  // pointer is null, file can't be opened
        printf("Usage: %s sourcewav file cannot be opened\n", argv[0]);
            exit(1);
        }
    printf("1");
    remvocals(source_file, destination_file); // remove vocals

    int closed_properly = fclose(source_file); // has source_file successfully closed?
    if (closed_properly != 0) {
        printf("Usage: %s sourcewav was not closed properly\n", argv[0]);
        exit(1);
    }
    fclose(destination_file);
    return 0;
}

最佳答案

您检查源文件而不对其进行初始化。另外,remvocals 有什么作用?

关于c - 查找 C 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28165687/

相关文章:

c - 如何在嵌入式 C while 循环中继续接收定时中断?

更改 C 函数参数中错误检查的类型?

c++ - x64 位的 C++/CLI DLL 和 Exe 应用程序崩溃

c++ - 在构造函数之后立即编程 SegFaults。 C++

c++ - C++实现哈希表时出现SIGSEGV错误

c - 使用通配符 (*) 作为第一个输入时,程序出现段错误

c - 在给定的 C 代码中查找错误

c - 确保字符串与 c 中的特定格式匹配

c++ - 与文件 i/o 相关的 c++ 程序末尾的段错误

c - 为什么在写入使用字符串文字初始化的 "char *s"而不是 "char s[]"时出现段错误?