字符串连接
现有连个文本文件1.txt和2.txt内容分别如下1.txt:
0001
0002
2.txt :
00
01
想编程分别将1.txt文件中的两横字符分别与2.txt的两行字符连接 并存入新的文件中
新生成的文件应为
000100
000101
000200
000201
编了好久都是错误的希望大神帮忙编译下简单代码
谢谢!
#include <stdio.h> #include <stdlib.h> int main(void) { const char* sourceFile1 = "1.txt"; const char* sourceFile2 = "2.txt"; const char* targetFile = "out.txt"; FILE* source1; FILE* source2; FILE* target; fopen_s(&source1, sourceFile1, "rt"); fopen_s(&source2, sourceFile2, "rt"); fopen_s(&target, targetFile, "wt"); char stringLine1[1024]; char stringLine2[1024]; while (fscanf_s(source1, "%s", stringLine1, _countof(stringLine1) - 1) == 1) { rewind(source2); while (fscanf_s(source2, "%s", stringLine2, _countof(stringLine2) - 1) == 1) { fprintf_s(target, "%s%s\n", stringLine1, stringLine2); } } fclose(source1); fclose(source2); fclose(target); return EXIT_SUCCESS; }