943,626 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 365
  • C++ RSS
Nov 17th, 2008
0

small problem with strings

Expand Post »
Don't know what is wrong with this, it's giving me an error on the 'if (isalpha(string[i]))' line..I had it working earlier but then decided to put it into a function and it's not working now. It's giving the error "expected primary-expression before '[' token " for that line and the one below it. Any ideas on what i've left out? The program is fairly simple. Takes in a string and I just wanna look at any words in that string...so far I only output the characters but i'll transfer them into an array or something later for use. Cheers to anyone who solves this stupid error for me..

#include<iostream>
#include<fstream>
#include<cstring>



using namespace std;

void trim(char string[], int num);

int main()
{
    char string[20];
    cout << "Input a string: " ;
    gets(string);
    
    
    cout << "You input: " << string;    
    trim(string, 20);
    
}


void trim(string[], int num)
{
          
           for(int i=0; i<num; i++)
            {
              if (isalpha(string[i]))
               {
                   cout << string[i];
               }
            }
                 
           cin.get();
          
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Marauder is offline Offline
25 posts
since Nov 2004
Nov 17th, 2008
1

Re: small problem with strings

>void trim(string[], int num)
This should be:
C++ Syntax (Toggle Plain Text)
  1. void trim(char string[], int num)
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: file I/O
Next Thread in C++ Forum Timeline: help with discrete math pseudo code loop question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC