Solved

Error I can't figure out

Posted on 1997-12-11
2
178 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

28 Experts available now in Live!

Get 1:1 Help Now