Object
Write a program to read a string and print its length.
Algorithm
- Declare a string str up to 80 characters.
- Read string str.
- Write length of string str, using strlen(str).
- Exit.
Flowchart

C++ Source Code
// program 93
#include<iostream>
#include <cstring>
using namespace std;
int main()
{
char str[80];
cout << "Enter the string: ";
cin.getline(str, 80);
cout << "\n";
cout << "'" << str << "' is " << strlen(str) << " characters long.";
return 0;
}
C Source Code
/*program 93*/
#include<stdio.h>
#include<string.h>
int main()
{
char str[80];
printf("Enter the string: ");
gets(str);
printf("\n\n");
printf("'%s' is %d characters long.\n", str, strlen(str));
return 0;
}
Output
Enter the string: Pakistan is my country.
‘Pakistan is my country.’ is 23 characters long.
