Solved

Error I can't figure out

Posted on 1997-12-11
2
177 Views
Last Modified: 2013-12-26
Here is the error I am getting on this bit of code:

Error   : pointer/array required
palindrome.cpp line 35   if(my_str[index_a] != my_str[index_b])


Here is the .cpp stuff:

#include <iostream.h>
#include "boolean.h"
//#include <string.h>
#include "strlib.h"

boolean flip_str(myString my_str);

int main( void )
{
      myString pal;
      
      cout << "Please type in a string: \n";
      cin >> pal;
                   
      if (flip_str(pal) == (TRUE)){
      cout << "The word " << pal << " is a palindrome" << endl;
      }
      else{
            cout << "The word " << pal << " is not a palindrome" << endl;
      }
      
}


boolean flip_str(myString my_str)
{
      int index_a = 0;
      int index_b = my_str.length() - 1;
      
      while (index_a < index_b) {
            if(my_str[index_a] != my_str[index_b])
                  return FALSE;
            index_a++;
            index_b--;
      }
      return TRUE;
}
0
Comment
Question by:charles_kline
2 Comments
 

Author Comment

by:charles_kline
Comment Utility
Edited text of question
0
 
LVL 1

Accepted Solution

by:
twall earned 100 total points
Comment Utility
The error means that the type of the variable you are applying the index or "[]" operator to is not a pointer, an array, or a class for which operator[] is defined.

You don't show the definition of the "myString" class, which is the type of the argument "my_str" in "flip_str".  Is this really the data type/class you want?

If you chagne the type of my_str from myString to a standard String, you'll have an implementation of operator[] which allows the string contents to be indexed.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 67
wait notify demo infinite loop 3 79
scoreUp challenge 14 47
sumHeights2  challenge 7 75
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now