use fgets

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
jedom
New poster
Posts: 2
Joined: Fri May 30, 2008 12:38 pm

use fgets

Post by jedom »

Can I use fgets function without problems?
my source code is:
while(fgets(linea, MAXLINEA, stdin)!=NULL)
{
if (strncmp(linea,"#",1)==0)
cont++;
strcat(larga, linea);

}
andmej
Experienced poster
Posts: 158
Joined: Sun Feb 04, 2007 7:45 pm
Location: Medellin, Colombia

Re: use fgets

Post by andmej »

I'm not sure, but I've always used getline(cin, myString).

Greetings.
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.

Are you dreaming right now?
http://www.dreamviews.com
maxdiver
Learning poster
Posts: 51
Joined: Tue Sep 04, 2007 2:12 pm
Location: Russia, Saratov
Contact:

Re: use fgets

Post by maxdiver »

Why not using just a gets()?
Megov
New poster
Posts: 3
Joined: Sun Apr 06, 2008 8:20 pm

Re: use fgets

Post by Megov »

And what are the problems?
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: use fgets

Post by lnr »

jedom wrote:

Can I use fgets function without problems?
my source code is:
while(fgets(linea, MAXLINEA, stdin)!=NULL)
{
if (strncmp(linea,"#",1)==0)
cont++;
strcat(larga, linea);
}

He used
if(strncmp(linea,"#",1)==0)
cont++;
Someone please tell me about the use of strncmp().
How to use it?
Post Reply

Return to “C++”