Array within Structures C++ – Program to find the length of string
Array within Structures C++ – Program to find the length of string
Let us see the program of finding the length of the string in C++ using array within structures.
Array within Structures C++ – Program to find the length of string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //Array with in structure demonstration by t4tutorials.com #include<iostream> #include<string.h> using namespace std; struct lengthstring { char str[4]; }; int main() { lengthstring s; int len,i; char str; for(i=0;i<4;i++) { cout<<"please enter string"<<endl; cin>>s.str; len=strlen(s.str); cout<<"The length of string is="<<len<<endl; } return 0; } |
Output
please enter your desired string
welcome
The length of your desired string is: 7
Comparison of An array of structure VS array within structures in C++