I have been asked to write a function that performs just as strlen would. I have no idea how to do anything on that without using cin.get() or cin.getline. How do I perfom get-like functions on already stored strings
I have been asked to write a function that performs just as strlen would. I have no idea how to do anything on that without using cin.get() or cin.getline. How do I perfom get-like functions on already stored strings
Count the char's in the string array until you reach null.
Fordy,
I know how to do it when entered at keboard but how do you count char on already stored string
ie
void main()
{
char source_str[128];
int res;
cout<<"enter string"<<endl;
cin>>source_str;
res=Cstrlen(source_str);
cout<<res;
}
int Cstrlen(const char source_str[])
{
count source_str characters here//how?
return num_char
}
You can just do this:
int main()
{
char string[] = {"String"};
int size=0;
while(string[size]){
size++;
}
cout << "The lenght is " << size;
}
the output should be 6.
this put the length of the String "Name" to an int "x":
int x = Name.length();
---------------------
Engineer223
alias: 322reenignE
Yoshi