Input by using gets function

后端 未结 3 2090
有刺的猬
有刺的猬 2020-12-06 23:08

In Below Code When I want to Enter Record of second student or >2 student .. Compiler skip Name Input and take Input for class and age .. What a problem please help me ?

3条回答
  •  北海茫月
    2020-12-07 00:09

    The problem is common enough. Try this:

    scanf("%d ", &a[i].age);
             ^ <--- This space will make scanf eat the remaining blanks
    

    There are C FAQs about this:

    • Scanf interlace
    • Scanf problems
    • Flushing stdin

    Secondary notes:

    • Don't use gets. Use fgets instead.

提交回复
热议问题