C++里面怎样实现对txt文件行列的统计
3个回答
展开全部
#include "stdafx.h"
#include<stdio.h>
void main()
{FILE *fp,*fp1;
int cap=0, i=1;
char mid,filename[10];
printf("Input the filename like *.txt!\n");
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL)
{printf("Can not open the file!\n");
}
if((fp1=fopen("stdout.txt","w+"))==NULL)
{printf("Can not open the file!\n");
}
while(!feof(fp))
{
mid=fgetc(fp);
if(mid=='\n') cap++;
}
fclose(fp);
if((fp=fopen(filename,"r"))==NULL)
{printf("Can not open the file!\n");
}
fprintf(fp1,"%d ",i++);
while(!feof(fp))
{
if(fputc(fgetc(fp),fp1)=='\n')
fprintf(fp1,"%d ",i++);
}
printf("cap=%d \n",cap+1);
fclose(fp);
fclose(fp1);
}
#include<stdio.h>
void main()
{FILE *fp,*fp1;
int cap=0, i=1;
char mid,filename[10];
printf("Input the filename like *.txt!\n");
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL)
{printf("Can not open the file!\n");
}
if((fp1=fopen("stdout.txt","w+"))==NULL)
{printf("Can not open the file!\n");
}
while(!feof(fp))
{
mid=fgetc(fp);
if(mid=='\n') cap++;
}
fclose(fp);
if((fp=fopen(filename,"r"))==NULL)
{printf("Can not open the file!\n");
}
fprintf(fp1,"%d ",i++);
while(!feof(fp))
{
if(fputc(fgetc(fp),fp1)=='\n')
fprintf(fp1,"%d ",i++);
}
printf("cap=%d \n",cap+1);
fclose(fp);
fclose(fp1);
}
追问
谢谢,我想要的是C++的,不是C语言的,数据格式如下
A B C D E F G H
X1 1 2 3 4 5
X2 10 11 12 13 14
X3 6 9 8 7 6
X4
X5
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cfile
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询