converting BOOL to INT

closed account (STR9GNh0)
how to convert this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

if (!charInWord (input_2, size2, *p))
...
...

bool charInWord (CharInfo *input, int size, CharInfo& temp)
{
	CharInfo *p = &input[0];
	
	for (int i = 0; i < size; i++)
	{
		if (p -> character == temp.character && p -> marker == ' ')
		{
			p -> character = '*';
			return true;
		}
		
		++p;
	}
	
	return false;
}	 


to use this statement instead?

 
int charInWord (char *, char);
Last edited on
Did you try to replace 'bool' with 'int'?
closed account (STR9GNh0)
well, i did and it works.

but the problem is.. i can only have 2

int charInWord (char *, char);

and that is it. currently my charInWord have got 3 arguments which erm.. doesn't seems quite fit.

is there any way to improve on it instead?
Last edited on
closed account (STR9GNh0)
hmm.. seems like there isn't any solution to it...
closed account (STR9GNh0)
i have been working for 5hours yet i still cant find any methods to overcome it...

any experts here?

or is my question too hard/impossible for any solutions?
Last edited on
What exactly are you trying to do? If you want an overloaded function with that signature, why don't you just write it?

EDIT: something like:

1
2
3
4
5
6
7
8
9
int charInWord(char* str, char ch)
{
    for(char* p = str; *p != 0; ++p)
    {
        if(*p == ch) *p = '*'; // notice the function is poorly named if it changes the string
        return 1; // I don't see why to use an int instead of a bool, unless you're programming in C
    }
    return 0;
}
Last edited on
closed account (STR9GNh0)
yeap, im programming in c. - nad thanks, i will try that out.
closed account (STR9GNh0)
kept getting:

cannot convert 'CharInfo' to 'char' for argument '2' to 'int charInWord(char*, char)'
You said you needed a function that takes a pointer to char and a char as arguments. You can't just pass it some struct. From your code above, I take it CharInfo has a char as member. So pass the char, not the struct. For instance:

1
2
3
4
5
6
7
char foo[] = "FooBar";
struct CharInfo bar;
bar.character = 'B';
if(charInWord(foo, bar.character))
{
    // ...
}
Last edited on
Topic archived. No new replies allowed.