使用scanf()按字符串和字符串读取

#include <stdio.h>
#define MAX_TOWN 10
int main(void)
{
  char initial = ' ';
  char name[80] = { ' ' };
  char age[4] = { '0' };
  printf("Enter your first initial: ");
  scanf("%c", &initial, sizeof(initial));
  printf("Enter your first name: " );
  scanf("%s", name, sizeof(name));
  fflush(stdin);

  if(initial  != name[0])
    printf("%s,you got your initial wrong./n", name);
  else
    printf("Hi, %s. Your initial is correct. Well done!/n", name );
    scanf("%[^,] , %[0123456789]", name, sizeof(name), age, sizeof(age));
    printf("/nYour name is %s and you are %s years old./n", name, age );
    return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266494.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论