方法1
void fun(int a, int b, long* c)
{
//45 12 1524
int c1, c2, c3, c4;
c1 = a % 10;//5
c2 = a / 10;//4
c3 = b % 10;//2
c4 = b / 10;//1
*c = (c4 * 1000 + c1 * 100 + c3 * 10 + c2);
}
int main()
{
int a, b;
long c;
printf("请输入a 和 b的值\n");
scanf("%d %d", &a, &b);
fun(a, b, &c);
printf("c的值为%ld", c);
return 0;
}
放法2
该方法是读取文本文件的内容,再写到新的文本文件
void fun(int a, int b, long* c)
{
int c1, c2, c3, c4;
c1 = a % 10;
c2 = a / 10;
c3 = b % 10;
c4 = b / 10;
*c = (c4 * 1000 + c1 * 100 + c3 * 10 + c2);
}
int main()
{
int a, b;
long c;
FILE* in = fopen("in.txt", "r");//事先创建好并且写入内容
FILE* out = fopen("out.txt", "w");//目录下不存在,会自动创建
if (in == NULL || out == NULL)
{
perror("error");
exit(1);
}
for (int i = 0; i < 10; i++)
{
fscanf(in, "%d %d", &a, &b);//读取内容
fun(a, b, &c);//合并
//将成品写到out.txt文本文件中去
fprintf(out, "a=%d b=%d c=%ld\n", a, b, c);//写内容
}
fclose(in);
fclose(out);
return 0;
}
in.txt资源文件在头顶哦