|
3鱼币
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #define MAX 100
- struct character
- {
- char A[MAX];
- }low[MAX];
- main()
- {
- int i,j;
- char ch;
- FILE *fp1,*fp2;
- if(!(fp1=fopen("E:\\11.txt","r")))
- {
- printf("can not open");
- exit(1);
- }
- if(!(fp2=fopen("E:\\111.txt","w")))
- {
- printf("can not write");
- exit(1);
- }
- while(ch!=EOF)//将文件11.txt内容以每行一个字符形式输入到low[].A;
- {
- for(i=0;i<MAX;i++)
- {
- ch=fgetc(fp1);
- for(j=0;j<MAX;j++)
- {
- if(ch!='\n')
- {
- low[i].A[j]=ch;
- ch=fgetc(fp1);
- }
- else
- {
- break;
- }
- }
-
- }
- }
- fclose(fp1);
- for(i=0;i<MAX;i++)//将文件11.txt内容以每行一个字符形式存到111.txt,重复的跳过
- {
- for(j=0;j<=i;j++)
- {
- if(strcmp(low[i].A,low[j].A)==0&&i==j)
- {
- fwrite(low[i].A,sizeof(struct character),1,fp2);
- fprintf(fp2,"\n");
-
- }
- }
- }
-
- fclose(fp2);
- }
复制代码
为什么我写入的文件会有两个回车
如果我把fprintf(fp2,"\n");
去掉就会变成
如何才能每个字符占一行?求大神指教
|
最佳答案
查看完整内容
#include
#include
#include
#define MAX 100
struct character
{
char A[MAX];
}low[MAX];
main()
{
int i,j, temp;
char ch;
FILE *fp1,*fp2;
if(!(fp1=fopen("E:\\11.txt","r")))
{
printf("can not open");
exit(1);
}
if(!(fp2=fopen("E:\\111.txt","wt")))
{
printf("can no ...
|