Solved

Error I can't figure out

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 83
MaxSpan challenge 9 96
canBalance challenge 34 85
fix34  challenge 9 120
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 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