6

everytime i try to input my string using gets() function, my compiler gives me warning like shown below. how to get rid of this. what am i doing wrong?

test.c:27:2: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(temp);
^
Chen-Tsu Lin
  • 22,876
  • 16
  • 53
  • 63
Chintan Patel
  • 310
  • 1
  • 2
  • 11

1 Answers1

27

Use fgets instead:

fgets(temp, sizeof(temp), stdin);

gets is deprecated because it's dangerous, it may cause buffer overflow.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294