I have to do the following exercise:
Enter a character text using the function
getchar( )
. Indicate the number of characters, words, and lines that form it. Show the order with explanatory signs. Consider as separators of valid words: space, tab and enter and keep in mind that counting words is not counting the number of separators. The entered text may contain any type of characters, including the enter.
The problem is that when I execute what I did, I get the following error:
invalid conversion from 'char' to 'const char*'
I would like to know how to solve it and if it is well stated the way I did to tell the words of the text. Thanks
#include <iostream>
using namespace std;
int cantpalabras(char *);
int main()
{
int longcarac,cantp;
char text;
printf ("Ingrese el texto \n");
text=getchar();
longcarac=strlen(text);
cantp=cantpalabras(text);
printf ("La cantidad de palabras es: %d \n", cantp);
system("PAUSE");
return 0;
}
int cantpalabras(char *at)
{
int cont=0;
int *punt=at;
while (*punt)
{ if (*punt='\n'||*punt='\t')
{ cont=cont+1;
punt++; } }
return cont; }