How do I keep reading from a keyboard in C while outputting results? -
i want read string , 4 integers display read read again string , 4 integers. want keep doing until end of file ( hitting ctrl + d). example :
tennis 4 2 3 2 (hit enter)
(the output)
helloworld 2 8 7 4 (hit enter)
(the output)
here tried :
#include <stdio.h> int main() { char name[30]; int won = 0; int lost = 0; int tie = 0; int streak = 0; int ch; while((ch = getchar()) != eof) { scanf("%s %d %d %d %d",name,&won,&lost,&tie,&streak); printf("%s%d%d%d%d",name,won,lost,tie,streak); } return 0; }
while(scanf("%29s%d%d%d%d",name,&won,&lost,&tie,&streak) == 5) printf("%s%d%d%d%d",name,won,lost,tie,streak);
from man -s3 scanf
:
these functions return number of input items matched , assigned
Comments
Post a Comment