converting BOOL to INT

Oct 23, 2010 at 4:19pm
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 Oct 23, 2010 at 8:39pm
Oct 23, 2010 at 4:22pm
Did you try to replace 'bool' with 'int'?
Oct 23, 2010 at 4:27pm
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 Oct 23, 2010 at 4:27pm
Oct 23, 2010 at 4:48pm
closed account (STR9GNh0)
hmm.. seems like there isn't any solution to it...
Oct 23, 2010 at 8:32pm
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 Oct 23, 2010 at 8:37pm
Oct 24, 2010 at 2:50pm
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 Oct 24, 2010 at 2:58pm
Oct 24, 2010 at 3:10pm
closed account (STR9GNh0)
yeap, im programming in c. - nad thanks, i will try that out.
Oct 24, 2010 at 3:23pm
closed account (STR9GNh0)
kept getting:

cannot convert 'CharInfo' to 'char' for argument '2' to 'int charInWord(char*, char)'
Oct 24, 2010 at 6:07pm
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 Oct 24, 2010 at 6:07pm
Topic archived. No new replies allowed.