#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp = NULL;
if ((fp = fopen("./01test.txt", "r")) == NULL)
{
perror("file open error\n");
return -1;
}
int count = 0;
char line[100]; // 假设每行最多100个字符
while (fgets(line, sizeof(line), fp) != NULL)
{
if(line(strlen(line)) - 1 == '\n')
{
count++;
}
}
fclose(fp);
printf("Line count: %d\n", count);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *srcfp;
FILE *destfp;
if ((srcfp = fopen("./01test.txt", "r")) == NULL)
{
perror("open file error\n");
}
if ((destfp = fopen("./dest.txt", "w")) == NULL)
{
perror("open file error\n");
}
char line[100];
while ((fgets(line, sizeof(line), srcfp)) != NULL)
{
fputs(line, destfp);
}
fclose(srcfp);
fclose(destfp);
return 0;
}