- This is my code…
- This will executing infinte times…
- can any help me to getting the paragraph without gets()
char str[100];int i=0;
for(cin>>str[i];str[i]!=’\n’
{++i;
cin>>str[i];
}
- If i use gets()function in cstring, iam getting the error like gets() function is out of scope…
hi @prashanthth not sure what exactly you mean by a “paragraph” but clearly your code doesn’t seem to be a good one. You don’t need to use a for loop.
Assumption:
I assume that you basically want to input a string which has spaces, and since you do not want to use a gets() you can use an alternative ie getline(). For that you can use this in c++:
int main()
{
char a[100];
cin.getline(a,100);
cout << a;
}
</pre>
If that doesn’t answer your question, i would request you be a little more specific as to what your requirement is, or even post the problem link which you are solving.
2 Likes
I dnt understnd y u can’t use gets man
agree with @yo_baby. You just need to include the proper header.
Don’t understand what you are asking but
-
if you want to use gets() then include stdio.h header.
#include<stdio.h>
int main(){
char a[100];
gets(a);
return 0;
}
-
If you don’t want to use gets() then you can use getline.