Hi, I'm pretty new to C++ and basically pretty new to all programming at all, have done something in java in school but never been programming something else than some scripts in work until now.

My problem now is when I try to compile this code I have here then I get a error's who are.
(17) : error C3861: 'count': identifier not found
(29) : error C2664: 'strlen' : cannot convert parameter 1 from 'char' to 'const char *'

What my assignment is to make a code that takes a text string and put's it through a function which returns me the number of chars in the text.

Here is the code I have now.

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	char pszString[256];
	int size = 0;

	cout << "Write a text that is under 256 characters" << endl;

	cin >> pszString;

	size = count(pszString);

	cout << "Your text is " << size << " characters long.";

	cin >> pszString;

	return 0;
}

int count ( char pszString )
{
	int size;
	size = strlen(pszString);
	return (size);
}

I hope you can help my something I will keep working on this and post in another code if I get something more working. I have let the code work without using a seperate function for the strlen argument.

Member Avatar for iamthwee

Try this:

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <cstring>
#include <iostream>

using namespace std;

int count (char[]);
int _tmain(int argc, _TCHAR* argv[])
{
	char pszString[256];
	int size = 0;

	cout << "Write a text that is under 256 characters" << endl;

	cin >> pszString;

	size = count(pszString);

	cout << "Your text is " << size << " characters long.";

	cin >> pszString;

	return 0;
}

int count ( char pszString[] )
{
	int size;
	size = strlen(pszString);
	return (size);
}

This work's now.

I also now understand what I was doing wrong with second error I should have null terminated the input into the function but why do I need to make this line? int count (char[]); Don't need to get the answer but it would be great since Im doing this to learn of thsi ;)

This work's now.

I also now understand what I was doing wrong with second error I should have null terminated the input into the function but why do I need to make this line? int count (char[]); Don't need to get the answer but it would be great since Im doing this to learn of thsi ;)

if you are passing an array to a function you have to tell it that it is an array by including the square brackets.

actually you can accomplish the code in this part of the program without making a new function count to calculate the characters.

the code is as follows, and it does the same thing for the program. i am assuming that you are not using that function else where.

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>


using namespace std;
 
 
int main()
{
	char pszString[256];
	int size = 0;
 
	cout << "Write a text that is under 256 characters" << endl;
 
	cin >> pszString;
 
	size = strlen(pszString);
 
	cout << "Your text is " << size << " characters long.";
 
	cin >> pszString;
 
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.