Solved

Error I can't figure out

Posted on 1997-12-11
2
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:charles_kline
ID: 1291717
Edited text of question
0
 
LVL 1

Accepted Solution

by:
twall earned 100 total points
ID: 1291718
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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