-4

I encountered a problem while working on a project. I know there are many simillar questions that are answered, but regarding this special one I could not find any help. I am getting the following error:

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

EDIT: I deleted the last lines of the code, but the error still occures at the line after the last '}'.

The project is about the PageRank Algorithm, using options in the console for choosing what algorithm is wished to be used. I am trying to read or use the options in the command line, but the error stops me from even looking at the semantic of my program.

/*
* 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);
}

One more thing: I encountered a problem regarding the lengh of the case 'h' : printf(), so I outcoded the text in multiple chars. If you need more information about anything, ask me.

2 Answers2

4

The compiler reports an error on line 42, but the source in your question is only 33 lines and it contains no ~ character. You need to show us the entire source you're compiling.

But I have a good guess.

The error message shows a line with a ~ character in column 1 and nothing following it. The vi (or vim) text editor uses ~ to mark lines on the screen that aren't part of the file. If you copy-and-paste a source file from a vi editor session, it's easy to copy too many lines and end up with an extra ~ at the end of your source file.

Edit the file, jump to the end, and delete that line.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • I made that, now it is telling me it's on line 41:1 – SteamyBanana Jun 04 '15 at 02:49
  • @SteamyBanana: Your joking, right? Did you even write anything of that code yourself? Just apply the proposesd rule iteratively. – too honest for this site Jun 04 '15 at 02:50
  • @Olaf I am serious. I am trying fixing this for an hour now, in my timezone it's in the middle of the night I am exhausted... By the rule, do you mean the while-loop? – SteamyBanana Jun 04 '15 at 02:59
  • @Olaf I wrote everything by myself with the official c reference. Please tell me if it is that trivial: what causes the error? I still have no clue – SteamyBanana Jun 04 '15 at 03:26
  • 1
    Then: **go to bed!!** The problem will be there for you *in the morning,* after you've had a good night's sleep ... a nice cup of coffee ... maybe a brisk morning walk. (Having done this crazy line of work professionally for more than 32 years now, I can say with certainty that you **must** know "when to turn the damned computer *off!!)"* "It's only ones and zeros," after all. *Keep that in mind!* – Mike Robinson Jun 04 '15 at 03:30
1

I got it now. My compiler (vim) added lines out of my sight. I used another editor and could delete the unnessecary code properly. Yes, was my bad all along. I am deeply sorry, it was a long day.