开发者

Gets related problem

#include <stdio.h>

int main ()
{
   FILE * pFile;
   int n;
   char name [开发者_StackOverflow100];

   pFile = fopen ("myfile.txt", "w");
   for (n = 0; n < 3; n++)
   {
     puts ("please, enter a name: ");
     gets (name);
     fprintf (pFile, "Name %d [%-10.10s]\n", n, name);
   }
   fclose (pFile);

   return 0;
}

this code gives me a warning in gcc saying 'gets is a dangerous function to use'...is there a workaround for it?


Yes it is fgets. Replace your call to gets with:

fgets(name, 100, stdin)

For more details see the docs - the two are not exactly the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜