| | |
small problem with strings
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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: 5
![]() |
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
Views: 262 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






