| | |
small problem with strings
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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();
} >void trim(string[], int num)
This should be:
This should be:
C++ Syntax (Toggle Plain Text)
void trim(char string[], int num)
New members chased away this month: 4
![]() |
Similar Threads
- Problem declaring class object array (C++)
- Reading in a file and taking a count (C++)
- I need some help with the following problem (C++)
- Splitting a string? (C)
- Problem with Perl syntax highlighter (DaniWeb Community Feedback)
- Problems with cin (char arrays|strings) (C++)
- problem in concatenation of 2 strings (C)
- Small problem with command line (C)
- Java practice questions (Java)
- can't proceed from here. (C++)
Other Threads in the C++ Forum
- Previous Thread: file I/O
- Next Thread: help with discrete math pseudo code loop question
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






