Help with pointers and strings

So im having trouble with pointers and strings. Im writing a program that asks a user to input a string then should count the string. I can do that but it also wants us to write a function that returns an integer and accepts a pointer to a C string as an argument. Any help would be appreciated. This is what I have
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include <iostream>
#include <string>

using namespace std;

//Function prototypes
int count(int, string);

//Main starts here
int main()
{
 string word;
 string *x = word;
 cin >> word;
 cout << word;

 count(total, word);
 cout << "This word has " << total << endl;

 system("PAUSE");
 return 0;

}

int count(int total,string word)
{
	total = word.length();
return total;
}
}
Last edited on
What is line 14 for? You should remove it, along with removing line 21 and reading this topic:
http://www.cplusplus.com/forum/beginner/1988/

Jose94ji wrote:
it also wants us to write a function that returns an integer and accepts a pointer to a C string as an argument.
Inside the function, just convert the C-style string to a normal string (you can even do this by calling your existing count function), and when calling the function take your normal strings and use .c_str() on them.
Last edited on
Topic archived. No new replies allowed.