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)



char inputString[100] = {0}; To get string input from the keyboard which one of the follow..

Answer / susie

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.

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Code Interview Questions

Is the following code legal? typedef struct a { int x; aType *b; }aType

1 Answers  


program to find the roots of a quadratic equation

14 Answers   College School Exams Tests, Engineering, HP, IIIT, Infosys, Rajiv Gandhi University of Knowledge Technologies RGUKT, SSC,


PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1 Answers  


program to Reverse a linked list

12 Answers   Aricent, Microsoft, Ness Technologies,


main() { 41printf("%p",main); }8

1 Answers  






C program to print magic square of order n where n > 3 and n is odd

2 Answers   Accenture,


main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }

3 Answers  


main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } } a. 0, 0 b. 0, 513 c. 512, 0 d. 0, -513

3 Answers   HCL, Logical Computers,


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

2 Answers   CSS, Wipro,


print a semicolon using Cprogram without using a semicolon any where in the C code in ur program!!

35 Answers   Tata Elxsi, TCS, VI eTrans,


why nlogn is the lower limit of any sort algorithm?

0 Answers  


Categories