gcc不再使用gets,改成fgets

来源:互联网 发布:青山知可子女机器人图 编辑:程序博客网 时间:2024/06/07 08:12

gcc不再使用gets,改成fgets

#include <stdio.h>#include <stdlib.h>#include <string.h>#define SIZE 128int main(){  char mychar, string[SIZE];  int i;  int count=0;      printf("Please enter your string: ");  fgets(string, SIZE, stdin);  printf("Please enter char to find: ");  mychar = getchar();  for (i = 0; (string[i] != '\0'); i++)    if (string[i] == mychar) ++count;  printf("The char %c appears %d times in the sentence: %s" ,mychar ,count, string);  return 0;}


gcc


0 0
原创粉丝点击