Let us see the String length Program Using Pointer to Structure in C++.
Program to find String length Using Pointer to Structure in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
//pointer to structure in C++ - demonstration by t4tutorials.com #include<iostream> #include<string.h> using namespace std; struct lengthstring { char str[10]; }; int main() { lengthstring *ptr,s; ptr=&s; int len; cout<<"please enter string"<<endl; cin>>(*ptr).str; len=strlen((*ptr).str); cout<<"The length of string is?"<<len<<endl; return 0; } |
Output
please enter your desired string
t4tutorials
The length of your desired string is: 11
Latest posts by Prof. Fazal Rehman Shamil (see all)
- List of Public service commissions - August 31, 2020
- Comparison of fee structure of Pakistani Universities - June 1, 2020
- Past Guess Paper of Auditing - May 12, 2020