Im having trouble sending a bool type to a function which returns a char string to a string.
I have provided the code below
/*
Name: bool2.cpp
Copyright:
Author: Toshkin
Date: 06/09/05 21:56
Description: passing string to boolean function returning boolean to
*/
#include <iostream>
#include <cstring>
using namespace std;
bool inout(char *string); // function prototype
char outin(char *string,bool *bl); //
int main()
{
char str1[5];
bool b;
cout <<"Please enter the word \"in\" or \"out\": ";
cin >>str1;
/*if (strcmp (str1,"in") == 0) { // redundant code....
b = true;
}
else {
b = false;
}
*/
b = inout(str1);
cout << boolalpha << b << endl;
cout <<"str1: "<<str1<<endl;
outin(str1,b);
cout <<"str1: "<<str1<<endl;
system("PAUSE");
return 0;
}
bool inout(char *string) // this works
{
if (strcmp(string,"in") == 0){
return true;
}
else if (strcmp(string,"out") == 0){
return false;
}
} // end inout
char outin(char *string,bool *bl) // this doesn't work
{
if (bl==1){
string = "in";
}
else if (bl==0) {
string = "out";
}
return string;
}
Im using Bloodshed DevC++ 4.9.9.2
Your help will be greatly appreciated.
Cheers Toshkin!!!