在线求助(c语言问题)
while(1)
{
strcpy (stri, "0");
strcpy (cpuname, CPU);
strcat (cpuname, stri);
i = 0;
//bzero(g_cpu_info,MAX_CPU_NUM);
while (get_parameters (cpuname, 'states:', "top.log", &m_stru_para) > 0)
{
sprintf (g_cpu_info[i].cpu_name, "%s", cpuname);
sprintf(g_cpu_info[i].cpu_used,"%f",
atof (m_stru_para.ca_elem_value[2]) +
atof (m_stru_para.ca_elem_value[4]));
printf ("%s used = %s\n", g_cpu_info[i].cpu_name, g_cpu_info[i].cpu_used);//testing!!!!!!!
*stri += 1;
i++;
strcpy (cpuname, CPU);
strcat (cpuname, stri);
}
sleep(20);
}
这段代码在第一次循环的时候能正确输出
CPU0 = 0.100000
CPU1 = 2.100000
但第二次循环的时候输出就为
CPU0 = nan
CPU1 = 2.100000
以后每次循环都是这样