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;
}
}

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.

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

you need to use getline() in that case to allows you to read more than just 1 character in at a time

Chris

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.