c - '(' token 之前的预期标识符或 '~'

标签 c debugging token getopt pagerank

我在做项目时遇到了问题。我知道有很多类似的问题得到了解答,但关于这个特殊的问题我找不到任何帮助。我收到以下错误:

Compiling main.c
main.c:42:1: error: expected identifier or '(' before '~' token
~
^
Makefile:47: recipe for target 'obj/main.o' failed
make: *** [obj/main.o] Error 1

编辑:我删除了代码的最后几行,但错误仍然发生在最后一个“}”之后的行。

该项目是关于 PageRank 算法的,使用控制台中的选项来选择希望使用的算法。我正在尝试读取或使用命令行中的选项,但该错误使我无法查看程序的语义。

/*
* main.c
*
*Programmierung 2 - Projekt 2 (PageRank)
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>

#include "utils.h" //is existing in the Directory


int main (int argc, char *const *argv) {
    //initialize the random number generator
    rand_init();

    printf("You gave %d command line arguments%c\n", argc-1, argc==1 ? '.' : ':');
    int graph;
    int i = 1;
    char * h = "-h show this help. \n";
    char * p = "...";
    char * m = "...";
    char * r = "...";
    char * s = "...";
    while ((graph = getopt(argc, argv, "hmprs")) != -1) {

        switch (graph) {
            default : printf("make -h | -m | -p | -r | -s "); break;
            case 'h' : printf("%s %s %s %s %s"), h, m, p, r, s); break;
            //this-like outcommended code like the one above
            //and again 
            //and once more
            //and a final one
        }
    printf(" - %s\n", argv[i]);
    i++;
    }
exit(0);
}

还有一件事:我遇到了有关 case 'h' 长度的问题:printf(),因此我将文本编码为多个字符。 如果您需要更多信息,请询问我。

最佳答案

编译器在第 42 行报告错误,但您问题中的源代码只有 33 行,并且不包含 ~ 字符。您需要向我们展示您正在编译的整个源代码。

但我有一个很好的猜测。

错误消息在第 1 列中显示了一行带有 ~ 字符的行,后面没有任何内容。 vi(或 vim)文本编辑器使用 ~ 来标记屏幕上不属于文件的行。如果您从 vi 编辑器 session 复制并粘贴源文件,很容易复制太多行,并在源文件末尾产生额外的 ~

编辑文件,跳到末尾,然后删除该行。

关于c - '(' token 之前的预期标识符或 '~',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30634041/

相关文章:

node.js - 如何使用 Node Express 在 mongodb 中存储 Json Web Token

c - 我该如何修复 C 中的 if 语句以使其按预期工作?

c++ - 嵌入 GDB 断点

c++ - QtCreator 在调试器中取消引用指针(使用库)

Delphi 2010-IDE 不断停止在 CPU 调试窗口

java - 将 token 保存到 ArrayList 中并在 Java 中比较每个 token

javascript - 未捕获的语法错误 : Unexpected token ILLEGAL

c - WIFEXITED、WEXITSTATUS等中 "W"的助记符是什么?

c - 如何将字符串复制到用户并在 Linux 内核读取函数中使用 offp

c - 为什么这个使用 fork() 和 wait() 的程序在我运行时输出 201?