如何在循环中使用scanf?
sscanf
?
char line[] = "100 185 400 11 1000";
int n, sum = 0;while (1 == sscanf(line, " %d", &n)) { sum += n; line += <number of bytes consumed by sscanf>}
sscanf
strtok
stdin
:
int n, sum = 0;while (1 == scanf(" %d", &n)) { sum += n; // stdin is transparently advanced by scanf call}
桃花长相依
相关分类