Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 31-03-2011, 08:32 PM   #1 (permalink)
Right Off the Assembly Line
 
bijay_ps's Avatar
 
Join Date: Mar 2011
Location: chennai
Posts: 44
Unhappy doubt between fscanf and fgets


whats the difference between fscanf and fgets in file handling(In C)?
__________________
Follow 7H3 G33K !nside YOU
bijay_ps is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 31-03-2011, 11:54 PM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: doubt between fscanf and fgets

fscanf does not perform bounds checking. fgets is likely going to be the better choice. You can then use sscanf() to evaluate it.

more info
IBM TPF Product Information Center
fscanf - C++ Reference
fgets - C++ Reference
scanf vs fgets?

BTW one more thing, never use scanf for input, use cin. Google it up if u want to know why, too many reasons for me to type
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 01-04-2011, 10:24 AM   #3 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: doubt between fscanf and fgets

Why suggest std::cin when the OP is using C, and confuse him?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline   Reply With Quote
Old 01-04-2011, 11:05 AM   #4 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: doubt between fscanf and fgets

^^ yes i thought it too

but the advantage(s) of C++ over C must be kept in mind
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 01-04-2011, 12:07 PM   #5 (permalink)
Right Off the Assembly Line
 
bijay_ps's Avatar
 
Join Date: Mar 2011
Location: chennai
Posts: 44
Default Re: doubt between fscanf and fgets

thanks guys....
__________________
Follow 7H3 G33K !nside YOU
bijay_ps is offline   Reply With Quote
Old 01-04-2011, 12:40 PM   #6 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: doubt between fscanf and fgets

Quote:
Originally Posted by arpanmukherjee1 View Post
but the advantage(s) of C++ over C must be kept in mind
???
Not sure how std::cin can be an advantage of C++ over C? Only advantage I can think of that you have to specify the format for the input in scanf which is not needed in std::cin. However both exhibit similar behaviour since they are usually implemented as line buffered.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline   Reply With Quote
Old 01-04-2011, 10:35 PM   #7 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: doubt between fscanf and fgets

^^ yes that, i'am sorry about the post.
i should have explained it.
reading this post now, i sound a lot like my coll professors

u explained it very well. thankyou
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx
- by clinton

Advertisement




All times are GMT +5.5. The time now is 12:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2