我有一个数据列表,我试图将字符存储在一个整数数组中,并将小数存储在双精度数组中。问题是:如果不阅读整条线,你怎么做?我想也许可以问是否有空间,停止阅读。但考虑到有多条线路,我该如何做呢?这是数据:
A 0.08030130328545595500
B 0.01404566680148545800
C 0.02309245337888202900
D 0.04680329046987134100
E 0.12475974957130967000
F 0.02262448732647651800
G 0.02092142515718645500
H 0.06495870199587520900
I 0.06832638626586488900
J 0.00118328558965393900
K 0.00796545073487383260
L 0.03678714564106335500
M 0.02553256208071077300
N 0.07071134182580297900
O 0.07759211410349403600
P 0.01653257210855475400
Q 0.00111309068179311220
R 0.06200383063640040700
S 0.06269909448568859700
T 0.09005003894146078300
U 0.02792921679195900500
V 0.00865068674018190480
W 0.02356209073861756000
X 0.00115988728703366340
Y 0.02033479628434954300
Z 0.00035933107595423293
答案 0 :(得分:0)
#include <stdio.h>
#include <stdlib.h>
int main(void){
int ch[32] = {0};
double num[32];
char word[32];
int i = 0, n, flipflop = 0;
while(1 == scanf("%31s", word)){//read word by word
if(flipflop){
num[i++] = atof(word);
} else {
if(*word && !word[1]){//a character
ch[i] = *word;
}
}
flipflop = !flipflop;
}
n = i;
for(i = 0; i < n; ++i){//test print
printf("%c %.20f\n", ch[i], num[i]);
}
return 0;
}