Question

I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes.

main.cpp

#include <iostream>

#include <string>

#include "functions.h"

using namespace std;

//definition of the main function.

//takes arguments from the command-line.

int main(int argc, char *argv[])

{

//Determine if you have enough arguments.

//If not, output a usage message and exit program

if (argc<2 || (argc == 2 && argv[1][0] == '-'))

{

//call the function printUsageInfo()

//with the program name

printUsageInfo("palindrome");

exit(0);

}

//declare the variables.

bool c = true, s = true;

//Loop through remaining arguments which are all input strings :

for (int i = 1; i < argc; i++)

{

//check whether the input has '-','c', 's' ,or both

if (argv[i][0] == '-')

{

if (strlen(argv[i]) == 2)

{

if (argv[i][1] == 's' || argv[i][1] == 'S')

s = false;

else if (argv[i][1] == 'c' || argv[i][1] == 'C')

c = false;

}

else

{

if (argv[i][1] == 's' || argv[i][1] == 'S' || argv[i][2] == 's' || argv[i][2] == 'S')

s = false;

if (argv[i][1] == 'c' || argv[i][1] == 'C' || argv[i][2] == 'c' || argv[i][2] == 'C')

c = false;

}

}

//Process each by calling isPalindrome function with flag values.

else

{

if (isPalindrome(argv[i], c, s))

cout << """ << argv[i] << "" is a palindrome. " << endl;

else

cout << """ << argv[i] << "" is not a palindrome. " << endl;

}

}

return 0;

}

functions.cpp

#include <iostream>
using namespace std;

void BackwardsAlphabet(char currLetter){
if (currLetter == 'a') {
cout << currLetter << endl;
}
else{
cout << currLetter << " ";
BackwardsAlphabet(currLetter - 1);
}
}

int main() {
char startingLetter;

startingLetter = 'z';
BackwardsAlphabet(startingLetter);

return 0;
}

functions.h

#ifndef FUNCTIONS_H

#define FUNCTIONS_H

#include <iostream>

#include <string>

using namespace std;

//declare the functions

bool isPalindrome(char str[], bool c, bool s);

bool checkPalandrome(char str[], int start, int end, bool c, bool s);

void printUsageInfo(string name);

#endif

Here are the directions for the assignment:

Background

Palindromes are character sequences that read the same forward or backword (e.g. the strings "mom" or "123 454 321"). Punctuation and spaces are frequently ignored so that phrases like "Dog, as a devil deified, lived as a god." are palindromes. Conversely, even if spaces are not ignored phrases like "Rats live on no evil star" are still palindromes.

Requirements

Command Line Parameters

The program name will be followed by a list of strings. The program will determine whether each string is a palindrome and output the results. Punctuation will always be ignored. An optional flag can preceed a term that modifies how the palindrome is determined.

Strings

Each string will be separated by a space on the command line. If you want to include a string that has spaces in it (e.g. "Rats live on no evil star"), then put quotes around it. The quote characters will not be part of the string that is read in.

Flags

Optional for the user

If present, flags always appear after the program name and before any strings are processed and apply to all subsequent strings processed.

Must start with a minus (-) sign followed by one or two flag values that can be capital or lower case. e.g. -c,-S, -Cs, -Sc, etc.

There are no spaces between starting minus (-) sign and flag(s).

Flags values are case insensitive.

c or C: Indicates that comparisons should be case-sensitive for all input strings. The default condition (i.e. if the flag is NOT included) is to ignore case-sensitivity. So, for example:

palindrome Mom should evalate as being a palindrome.

palindrome -c Mom should not evalate as being a palindrome.

s or S: Indicates that comparisons should not ignore spaces for all input strings. The default condition (i.e. if the flag is NOT included) is to ignore spaces. So, for example:

palindrome "A nut for a jar of tuna" should evalate as being a palindrome.

palindrome -s "A nut for a jar of tuna" shouldnot evalate as being a palindrome.

Options can appear in different flags, e.g. you can use -Sc or-S -c

The same flag cannot appear more than one time prior to a term. If it does, print a usage statement and exit program.

Code Expectations

Your program should only get user input from the command line. (i.e. "cin" should not be anywhere in your code).

Required Functions:Function that prints program usage message in case no input strings were found at command line.

Name: printUsageInfo

Parameter(s): a string representing the name of the executable from the command line.

Return: void.

Recursive function that determines whether a string is a character-unit palindrome.

Name: isPalindrome

Parameter(s): an input string, a boolean flag that considers case-sensitivity when true, and a boolean flag that does not ignore spaces when true.

Return: bool.

All functions should be placed in a separate file following the code organization conventions we covered.

Program Flow

Your program will take arguments from the command-line.

Determine if you have enough arguments. If not, output a usage message and exit program.

If flags are present.

Process and set values to use when processing a palindrome.

Loop through remaining arguments which are all input strings:

Process each by calling isPalindrome function with flag values.

Output results

Program Flow Notes:

Any time you encounter a syntax error, you should print a usage message and exit the program immediately.

Hints

Remember rules for a good recursive function.

Recommended Functions to write:
Note: You could combine these into a single function. e.g. "preprocessString"tolower - convert each letter to lowercase version for case insensitive comparisons.

Parameter(s): a string to be converted to lower case

Return: a string with all lower case characters

removePunctuation - Remove all punctuation marks possibly including spaces.

Parameter(s): a string and a boolean flag indicating whether to also remove spaces

Return: a string with punctuation/spaces removed

Existing functions that might help:

tolower

erase

substr

isalnum

Example Output

Note: you will probably only see the ./ if running on build.tamu.edu.

./palindrome
Usage: ./palindrome [-c] [-s] string ...
  -c: case sensitivity turned on
  -s: ignoring spaces turned off

./palindrome -c
Usage: ./palindrome [-c] [-s] string ...
  -c: case sensitivity turned on
  -s: ignoring spaces turned off

./palindrome Kayak
"Kayak" is a palindrome

./palindrome -c Kayak
"Kayak" is not a palindrome.

./palindrome -C Kayak
"Kayak" is not a palindrome.

./palindrome -c kayak
"kayak" is a palindrome.

./palindrome "Test Set"
"Test Set" is a palindrome.

./palindrome -sc "Test Set"
"Test Set" is not a palindrome.

./palindrome -s -c "Test Set"
"Test Set" is not a palindrome.

./palindrome -s -s "Test Set"
"Test Set" is not a palindrome.

./palindrome -scs "Test Set"
"Test Set" is not a palindrome.

./palindrome Kayak madam "Test Set" "Evil Olive" "test set" "loop pool"
"Kayak" is a palindrome.
"madam" is a palindrome.
"Test Set" is a palindrome.
"Evil Olive" is a palindrome.
"test set" is a palindrome.
"loop pool" is a palindrome.

./palindrome -s Kayak madam "Test Set" "Evil Olive" "test set" "loop pool"
"Kayak" is a palindrome.
"madam" is a palindrome.
"Test Set" is not a palindrome.
"Evil Olive" is not a palindrome.
"test set" is not a palindrome.
"loop pool" is a palindrome.

./palindrome -c Kayak madam "Test Set" "Evil Olive" "test set" "loop pool"
"Kayak" is not a palindrome.
"madam" is a palindrome.
"Test Set" is not a palindrome.
"Evil Olive" is not a palindrome.
"test set" is a palindrome.
"loop pool" is a palindrome.

./palindrome -c -s Kayak madam "Test Set" "Evil Olive" "test set" "loop pool"
"Kayak" is not a palindrome.
"madam" is a palindrome.
"Test Set" is not a palindrome.
"Evil Olive" is not a palindrome.
"test set" is not a palindrome.
"loop pool" is a palindrome.

Sorry for the extra info, thank you in advance!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

>>I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp

This is because strlen() is a function which is defined in <string.h> header file.

The header file used in your main.cpp file is #include <string>. Replace it with #include <string.h>

This will fix your issue.

Add a comment
Know the answer?
Add Answer to:
I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • For this assignment, you will create a program that tests a string to see if it...

    For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is...

  • Attached to this assignment as a separate document is the C++ code for a program that...

    Attached to this assignment as a separate document is the C++ code for a program that determines if a given string is a palindrome or not. A palindrome is a word that is spelled the same backward or forward. "bob" is an example of a palindrome. The program is sometimes a talking point during lecture, and may not fully adhere to the many bobisms I've been telling you about. In fact, it may not entirely work but that wasn't its...

  • Stack help. I need help with my lab assignment. Complete a method for a class named...

    Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • Language is in C. Need help troubleshooting my code Goal of code: * Replace strings with...

    Language is in C. Need help troubleshooting my code Goal of code: * Replace strings with a new string. * Append an s to the end of your input string if it's not a keyword. * Insert a period at the end, if you have an empty input string do not insert a period Problems: //Why does my code stop at only 2 input strings //If I insert a character my empty string case works but it's still bugged where...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • The provided code is my solution, stripped of the details needed to make it work. It...

    The provided code is my solution, stripped of the details needed to make it work. It is not a “good” program. It lives in a single file, does not use classes, and it has those evil global variables. That is by design. I want to to craft code. Use my code as a guide to help you put together the needed parts. #include #include #include // defaults const int MAX_STEPS = 100; // how long do we run the simulation...

  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT