Computer Science, asked by srishtichandra2009, 1 year ago

Write a program to input any sentence and count how many words, characters and spaces are there in c++ without using any function and array....


Please fast it's urgent

Answers

Answered by manas001
0
C++ Strings

In this article, you'll learn to handle strings in C. You'll learn to declare them, initialize them and use them for various input/output operations.



String is a collection of characters. There are two types of strings commonly used in C++ programming language:

Strings that are objects of string class (The Standard C++ Library string class)C-strings (C-style Strings)

C-strings

In C programming, the collection of characters is stored in the form of arrays, this is also supported in C++ programming. Hence it's called C-strings.

C-strings are arrays of type charterminated with null character, that is, \0 (ASCII value of null character is 0).

How to define a C-string?

char str[] = "C++";

In the above code, str is a string and it holds 4 characters.

Although, "C++" has 3 character, the null character \0 is added to the end of the string automatically.

Alternative ways of defining a string

char str[4] = "C++"; char str[] = {'C','+','+','\0'}; char str[4] = {'C','+','+','\0'};

Like arrays, it is not necessary to use all the space allocated for the string. For example:

char str[100] = "C++";

Example 1: C++ String to read a word

C++ program to display a string entered by user.

#include <iostream> using namespace std; int main() { char str[100]; cout << "Enter a string: "; cin >> str; cout << "You entered: " << str << endl; cout << "\nEnter another string: "; cin >> str; cout << "You entered: "<<str<<endl; return 0; }

Output

Enter a string: C++ You entered: C++ Enter another string: Programming is fun. You entered: Programming


srishtichandra2009: Can you please make a program ..... please
Similar questions