expected init-declarator?

I can't figure out how to get rid of this error. The trouble is on line 44. Does anyone have any idea what's wrong? It's probably something simple, but I have no clue what to do.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

const int PAUSE_DURATION = 400;
const int FREQUENCY = 500;
const int BEEP_DOT = 250;
const int BEEP_DASH = 600;

int size;
//int idx;
                    

void beep_sequence( char* dot_or_dash, int idx )
{    
    for ( idx = 0; idx < size; ++idx )
    {
    //if ( *dot_or_dash )
    //{
            
            switch( *dot_or_dash )
            {
            case '.':
                 {
                     cout << '.';
                     Beep( FREQUENCY, BEEP_DOT );
                     break;
                 }
            case '-':
                 {
                     cout << '-';
                     Beep( FREQUENCY, BEEP_DASH );  
                     break;
                 }
            }
            ++dot_or_dash;
    //}
    }
}

void process_one_word( char* pchar )
char* codes[] = { ".-", "-..." }; // expected init-declarator before "char"
{                
    int idx;
    while ( *pchar )
    {    
        switch( *pchar )
        {
        case 'a':
            {
                idx = 0;
                size = 2;
                beep_sequence( codes[ idx ] );  
                break;
            }
        case 'b':
            {
                idx = 0;
                size = 2;
                beep_sequence( codes[ idx ] );  
                break;
            }
        }
        
        ++pchar;
    }
    //Sleep( PAUSE_DURATION );
    
}

int main( int argc, char* argv[] )
{    
    int idx;
    for ( idx = 1; idx < argc; ++idx )
    {
        process_one_word( argv[ idx ] );
    }
    return 0;
}

Last edited on
1
2
3
void process_one_word( char* pchar )
char* codes[] = { ".-", "-..." }; // expected init-declarator before "char"
{                


Move char* codes[] inside the left bracket of void process_one_word. Also, you have beep_sequence as taking two arguments, but only pass it one.
//This program calculates the area of a ring
#include<iostream.h>
// function declaration.
double circleArea(double)
main() //First error=expected init-declarator before "main" , 2nd error=expected `,' or `;' before "main"
{
double rad1;
double rad2;
double ringArea;
cout<<"Please enter the outer radius value:";
cin>>rad1;
cout<<"Please enter the radius of the inner circle:";
cin>>rad2;
ringArea=circleArea(rad1)-circleArea(rad2);
cout<<"Area of the ring having inner raduis"<<rad2<<"and the outer radius"<<rad1<<"is"<<ringArea;
}

ANY BODY COULD HELP ON THIS I AM USING Dev-C++, two errors are coming by compiler I've written them after main() as comments.
@ZGalhardo

Line 43 needs a semicolon on the end:

43 void process_one_word( char* pchar ); // <= semicolon ; here!

EDIT: Oh no, that's not it. I think line 43 and line 44 need swapping round!
Last edited on
@Muhammad:
-the 1st error can be solved by changing main() into int main()
-the 2nd error can be solved (as devc++ states) by adding a ; after double circleArea(double)

That should solve your problem (:

@Zgalhardo:
Sorry, I can't find the problem (probably because I'm to much of a beginner :P) so sorry for adding a (for you) useless post to this thread :)
@ kaduuk

Thanks a lot, it run fine by adding ; after double circleArea(double).

And 2ndly your post is not useless.
Topic archived. No new replies allowed.