可以使用文件操作和字符串处理函数来实现将读取的文件内容去掉空白的内容,然后将其连起来的功能。下面是一个示例代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void removeWhitespace(char* str) {
int i, j;
for (i = 0, j = 0; str[i] != '\0'; i++) {
if (str[i] != ' ' && str[i] != '\t' && str[i] != '\n') {
str[j++] = str[i];
}
}
str[j] = '\0';
}
int main() {
FILE* file = fopen("input.txt", "r");
if (file == NULL) {
printf("Failed to open the file.\n");
return 1;
}
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
char* content = (char*)malloc(fileSize + 1);
if (content == NULL) {
printf("Failed to allocate memory.\n");
fclose(file);
return 1;
}