small problem with strings

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 24
Reputation: Marauder is an unknown quantity at this point 
Solved Threads: 0
Marauder's Avatar
Marauder Marauder is offline Offline
Newbie Poster

small problem with strings

 
0
  #1
Nov 17th, 2008
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();
          
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: small problem with strings

 
1
  #2
Nov 17th, 2008
>void trim(string[], int num)
This should be:
  1. void trim(char string[], int num)
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC