我有以下部分代码:
i = 0;
while (ptr != NULL)
{
if (i == 0)
strcat(machine, ptr);
if (i == 2)
strcat(number, ptr);
if (i == 4)
strcat(hr, ptr);
if (i == 6)
strcat(dw, ptr);
if (i == 8)
strcat(vcc, ptr);
i++;
}
printf("Final: %s, %s, %s, %s, %s\n", machine, number, hr, dw, vcc);
我有这些结果:
Final: 3, 34, 56, 67, 56
如何将它们保存在位置 5-9 的 10 位置数组中?变成这样:
0 0 0 0 0 3 34 56 67 56
我写了下面的代码但是因为不知道如何在表中传递&machine、&number、&hr、&dw、&vcc
FILE *ft = fopen("Desktop/mytext.txt","a+");
struct tm *tp;
time_t t;
char s[80];
t = time(NULL);
tp = localtime(&t);
strftime(s, 80, "%d/%m/%Y %H:%M:%S", tp);
char table1[1][10];
for(int i = 0; i<1; i++)
{
fprintf(ft,"%s ",s);
for(int j = 0; j<10; j++)
fprintf(ft,"%d ",table1[i][j]);
}