Hi everyone, I have been learning about strings and successfully wrote my first string program which counts the characters in a given sentence. The problem that I ran into was that I wanted the program to count a string of characters that was entered by the user (no matter what it was)
e.g.
My name is Glenn
output: 16 (including spaces)
This is the program I was able to successfully run
This is the program that I am trying to write so that it returns the number of characters input by the userCode:#include<iostream.h> #include<cstring> int main() { char *string_a= "This is a test"; cout<<"The length of \""<<string_a<<"\"is "<<strlen (string_a)<<endl; return 0; }
I thought that the program was written correctly because it returns no (compiling) error but when it compiles Visual C returns an error and closes my program out.Code:#include<iostream.h> #include<cstring> int main() { char *string; cout<<"What is your string"; cin>>string; cout<<" The length of "<<string<<" is " << strlen (string)<<endl; return 0; }
![]()
Can someone please poing me in the right direction....Should I start over??
Thank you very much



LinkBack URL
About LinkBacks



