Visual Studio Error 2440 char/pointer

//I know this is very basic. I found plenty of posts about error 2440 but nothign too too close to the top that looked that relevant.

I have tried passing wstring as a pointer, array and anything else I can think of.

Probably just the late hour, but what am I screwing up please?

Thank you,
J


#include<iostream>
#include<cctype>

using namespace std;

int wordCount(char);

int main()
{
const int WSIZE = 100;
char *wstring[WSIZE];

wstring = new char[WSIZE];

cout << "Enter a sentence to count the words ";
cin.getline(wstring, WSIZE);

cout << "The sentence contains " << wordCount(wcount) << " words.";

return 0;
}


int wordCount(char wstring)
{
//int wsize = strlen(wstring[100]); //length of string
int wcheck = 0; //index for string position
int wcount = 0; //counter of words found

//increment char count until finding first alpha
while(!isalpha(wstring[wcheck]))
wcheck++;

wcount++;

do{
if(!isspace(wstring[wcheck]) && !isalpha(wstring[wcheck + 1]))
wcount++;

wcheck++;
}while(wcheck < wsize - 1);

return wcount;
}

error C2440: '=' : cannot convert from 'char *' to 'char *[100]'
error C2109: subscript requires array or pointer type
Last edited on
You are mixing arrays and dynamic arrays
1
2
3
char *wstring[WSIZE];

wstring = new char[WSIZE];

For non-dynamic use this syntax: char wstring[WSIZE];
For dynamic use this instead: char *wstring = new char[WSIZE];

int wordCount(char wstring) You missed a * : int wordCount(char *wstring) int wsize = strlen(wstring[100]); remove subscripting: int wsize = strlen(wstring);

Please use [code][/code] tags
Thanks, That helped.
Topic archived. No new replies allowed.