好友
阅读权限10
听众
最后登录1970-1-1
|
jtwc
发表于 2022-2-12 15:50
各位老师,c语言中如何将变量double a22写入数组不再变,能在后面的循环中能提取呢?谢谢了,案例如下:
#include <stdio.h>
#include <string.h>
int main()
{
char Result[1024] = {0};
char *t;
int j = 1;
//读取文件
FILE *fp = fopen("y:\\1.txt", "rb");
fread(Result, 1024, 1, fp);
fclose(fp);
//将换行符替换为分割文本的制表符
for (int i = 0; i < 1024; i++)
{
if (Result[i]=='\r' && Result[i+1] == '\n')
{
Result[i] = '\t';
Result[i+1] = '\t';
}
}
t = strtok(Result, "\t");
while (t)
{
t = strtok(NULL, "\t");
j++;
if (j==95 && t!=NULL)
{
printf("第%d组:%s", j, t);
char a[] = { 0 };
sprintf(a, "%s\n", t);
std::string a1= a;
double a2 = std::stod(a1);
}
}
while (1)
{
//读取文件
FILE *fp = fopen("y:\\2.txt", "rb");
fread(Result, 1024, 1, fp);
fclose(fp);
//将换行符替换为分割文本的制表符
for (int i = 0; i < 1024; i++)
{
if (Result[i]=='\r' && Result[i+1] == '\n')
{
Result[i] = '\t';
Result[i+1] = '\t';
}
}
t = strtok(Result, "\t");
while (t)
{
t = strtok(NULL, "\t");
j++;
if (j==5 && t!=NULL)
{
printf("第%d组:%s", j, t);
char b[] = { 0 };
sprintf(b1, "%s\n", t);
double b2 = std::stod(b1);
}
i f (a2>b2)
{
printf("%f\n", a2-b2);
}
}
getchar();
return 0;
} |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|