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