-
Strlen(...)
Code:
#include <iostream.h>
int main()
{
char x;
while(strlen(x)) < 8
{
cin >> x;
}
return 0;
}
This code should allow the user to type in a word in x, but should automatically go on to the next operation when the length of x reaches 8. I can't compile it due to an error on the WHILE line, how can I solve it ?
-
> while(strlen(x)) < 8
while(strlen(x) < 8 )
-
Code:
char text[100];
do {
cin.width(100);
cin >> text;
}while(strlen(text) < 8);
-
Code:
#include <iostream.h>
int main()
{
char x;
while(strlen(x) < 8)
{
cin >> x;
}
return 0;
}
7 C:\3.cpp
passing `char' to argument 1 of `strlen(const char *)' lacks a cast
Damn...
-
strlen expects char*, not char
This might do what you are looking for:
Code:
char str[9];
for(int i = 0; i < 8; ++i)
cin >> str[i];
str[8] = '\0';
-
Thanks... But then how do you use Strlen ?
-
In the above example, you could use strlen(str) since str is a char*. You just can't use it on a char (since its length is always 1).