954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

small problem with strings

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();

}

Marauder
Light Poster
25 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

>void trim(string[], int num)
This should be:

void trim(char string[], int num)
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You