0

the below code is to allow user to enter many strings of characters until he enters a fullstop (.)
Please tell me how can i calculate the total number of strings the user has entered.

#include <iostream>
void main()
{
char a[80];
int i,c=0;
for(i=0;;i++)
{
cin>>a;
if(a=='.')
break;
}
}

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by bhoot_jb
0

well, i am quite confused here. You mean to say you want to take input of several strings in a single character array? :|

infact, here you are asking for a single character everytime :
> cin >> a

if you meant to count the number of characters, then you may do it using some function like strlen(), or you may put a counter along with input.

Also, the array here is certainly unstable, without '\0' null character.

0

i want the string for eg: "hello this is c++" like this .

0

If you want only a single string, then its getline().

If you want several strings, then a single array certainly wont do. I wonder how will you differentiate between strings. As you said, if you use '.', still wouldnt it be better if you use a 2-D array of characters, or an array of character pointers?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.