Logo 
Search:

C Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C ProgrammingRSS Feeds

C programming practical question 169

  Shared By: Adah Miller    Date: Jan 24    Category: C Programming    Views: 66

Answer:

char inputString[100] = {0};

To get string input from the keyboard which one of the following is better?

1) gets(inputString)
2) fgets(inputString, sizeof(inputString), fp)


Answer & Explanation:
The second one is better because gets(inputString) doesn't know the size of the string passed and so, if a very big input (here, more than 100 chars) the charactes will be written past the input string. When fgets is used with stdin performs the same operation as gets but is safe.

Share: 
 

Didn't find what you were looking for? Find more on C programming practical question 169 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: