expected primary-expression before "int"

Hi.
The error is:
27 G:\Test_suite\HW2_Hooshdaran.cpp expected primary-expression before "int"


and the program is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <io.h>
#include <string>
#include <cstring>
#include <map>
#include <fcntl.h>

using namespace std;

#define FILENAME "G:\\MS_shirazu\\TextMining\\HWs\\TWA\\TWA\\Bass.Test"

int main()
{
    char buffer[120000] = {0};
    
    int fh = _open(FILENAME, O_RDONLY);
    _read(fh, buffer, 120000 );
    
    
    int i=0;
    char *pc1;
    char *pc2;
    
    pc1 = strstr(buffer, "<context>");  //searching for the first occurrence of <context>
    pc2 = strstr(buffer, "</context>");
    
   int contextsNo++;
    
    pc1 +=10;
    
    while(pc1 != 0)
    {
              pc1 = strstr(pc1, "<context>");  //searching for the next occurrence of <context>
           //   ++contextsNo;
    }

    
    while(1);
    
    return 0;
}


Why is it that line 27 errs?

Thanks in advance
Last edited on
It just makes no sense to increase a variable while creating. What are you trying to do?
I am trying to count the number of occurrencers of "<context>".

But it is an absurd error!
Last edited on
it's an absurd line of code.
The compiler's trying it's best to interpret it.
But it is an absurd error!

You have absurd expectations.

If I do this in the context of a function:
int a;

what value does a have?

It has some garbage value. What does increasing that value by 1 give you? A garbage value. So what should: int a++; do? Nothing sensible.

Check if lines 24 and 25 succeed. Based on that initialize contextsNo to 0 or 1 on line 27. Check if line 33 is successful. Based on that, increment contextsNo or not.
But the error message is very exotic, absurd, misleading. Believe me.It has nothing to do with the int.
The important thing is that the compiler identifies the line and point where there is a problem. Your compiler has done that for you.

As for it appearing absurd, well I've often had that opinion too. But, as you gain more experience, very often what previously seemed absurd starts to appear very clear and meaningful.

Also, the actual wording of the message may depend upon the compiler. Mine gives:
[Error] expected initializer before '++' token
and that is absolutely precise in highlighting the exact problem with the code - but it may only be clear if you understand what it is saying.

Topic archived. No new replies allowed.