Question
Hi, I need some help from my C++ program. The code that I put below needs to have void main(void) instead of int main() since
Hi, I need some help from my C++ program. The code that I put below needs to have void main(void) instead of int main() since the requeriments have oid main(void) instead of int main(). It is possible to use main(void)? Because I have problems compiling the code. Thanks.
Code:
#include
using namespace std;
struct StringRec
{
int strLen;
char theStr[256];
};
// adds one character to the string
void AddChar(StringRec& str, char theCh);
// adds one character to the string
void OutputString(StringRec str);
// outputs the string and the length of the string
bool CheckString(StringRec str);
// returns true if string is a palindrome, false otherwise
void main(void)
{
StringRec theString;
char theChar;
theString.strLen = 0;
cout << "Enter a string: ";
cin.get(theChar);
while (theChar != ' ')
{
AddChar(theString, theChar);
cin.get(theChar);
}
OutputString(theString);
if (CheckString(theString))
cout << "The string is a palindrome ";
else
cout << "The string is not a palindrome ";
}
// add character one by one in char array and increase strlen by one every time
void AddChar(StringRec& str, char ch)
{
str.theStr[str.strLen] = ch;
str.strLen++;
}
//print element of char array one by one until upto strlen
void OutputString(StringRec str) {
int i;
for (i = 0; i cout << str.theStr[i]; } } //print element of char array one by one until upto strlen // to check string or char array is palindrome or not //compare the first element with last //then second with second last......and so on......example.......abcba // if not follow then break the loop bool CheckString(StringRec str) { int i, f = 0; for (i = 0; i { if (str.theStr[i] != str.theStr[str.strLen - 1 - i]) { f = 1; break; } } if (f == 0) return true; else return false; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started