Error with strcmp

Hey,

I'm trying to recursively go through a C-Style char array to find a letter.
Unfortunately the strcmp function that I'm using is giving me a error I was hoping someone could enlighten me on the topic.

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
#include <iostream>
#include <cstring>

using namespace std;

bool path(char map[31], int col);

int main()
{
    bool returnValue = false;
    char map[31] = "|                      G    |";

    returnValue = path(map, 0);

    if(returnValue == true)
        cout << "Found" << endl;
    else if(returnValue == false)
        cout << "No end point" << endl;

    return 0;
}

bool path(char map[31], int col){
    char g = 'G';
    bool rc = false;

    if(strcmp(g, map[col]))
        rc = true;
    else
        rc = false;

    if(map[col] != 'G')
        path(map, col + 1);
    else if(col == 30)
        path(map, col - 1);

    return rc;
}


Thanks
Firstly,
char *position=strchr("Hello, World!",'o');
Secondly, searching for values in unsorted arrays is done by iteration, not recursion.
Thirdly, your recursion is infinite.
Last edited on
I agree, that iteration would have been better but this is the way its supposed to be done for an assignment at school. Which immediately rules out both iteration and strchr. Recursion is the only option.

Any hints on why mine is infinite?
Topic archived. No new replies allowed.