高分悬赏3题简单C语言编程题
1统计字母、数字和字符统计一个文本文件中字母、数字及其他字符各有多少个。2删除注释将一个C语言源程序文件中所有注释去掉后,存入另一个文件。3文件合并文本文件a1.txt和...
1 统计字母、数字和字符
统计一个文本文件中字母、数字及其他字符各有多少个。
2 删除注释
将一个C 语言源程序文件中所有注释去掉后,存入另一个文件。
3文件合并
文本文件a1.txt 和a2.txt 中包含若干从小到大排过序的整数,现要求把两个文件中的数据合起来,仍按从小到大顺序写入文件a3.txt 中,试编写相应程序。 展开
统计一个文本文件中字母、数字及其他字符各有多少个。
2 删除注释
将一个C 语言源程序文件中所有注释去掉后,存入另一个文件。
3文件合并
文本文件a1.txt 和a2.txt 中包含若干从小到大排过序的整数,现要求把两个文件中的数据合起来,仍按从小到大顺序写入文件a3.txt 中,试编写相应程序。 展开
6个回答
展开全部
太简单了~
#include "stdio.h"
#include "conio.h"
main()
{
FILE *fp;
fp=fopen("text1.txt","r");
char ch;
int totalnum =0;
int totalwords =0;
while(ch!=EOF)
{
ch=fgetc(fp);
if(((ch>='A')&&(ch<='Z'))||((ch>='a')&&(ch<='z')))
{
totalwords++;
}
else if((ch>='0')&&(ch<='9'))
{
totalnum++;
}
}
printf("totalwords : %d\n",totalwords);
printf("totalnum :%d\n",totalnum);
fclose(fp);
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LINE 1000
#define RMV "/* XXXXX */"
int main()
{
char sLine[MAX_LINE];
char *pPos;
freopen("exam.c","rb",stdin);
freopen("exam.out","wb",stdout);
while (gets(sLine))
{
while (pPos = strstr(sLine,RMV))
{
*pPos = '\0';
strcat(sLine,pPos+strlen(RMV));
}
puts(sLine);
}
return 0;
}
#include<stdio.h>
void main()
{
FILE *f1,*f2,*f3;
int a,b;
f1=fopen("a1.txt","r");
f2=fopen("a2.txt","r");
f3=fopen("a3.txt","w");
//a=getw(f1);
fscanf(f1,"%d",&a);
//b=getw(f2);
fscanf(f2,"%d",&b);
while(!feof(f1)&&!feof(f2)) //两个文件都没结束时,执行循环、比较
{
if(a<=b){
fprintf(f3,"%d ",a);
fscanf(f1,"%d",&a);
}else{
fprintf(f3,"%d ",b);
fscanf(f2,"%d",&b);
}
}
if(feof(f1)) //文件a1.txt结束时,把a2.txt中的数全部输入a3.txt
{
if(a<=b){
fprintf(f3,"%d ",a);
fprintf(f3,"%d ",b);
}else{
fprintf(f3,"%d ",b);
fprintf(f3,"%d ",a);
}
while(!feof(f2)){
fscanf(f2,"%d",&b);
fprintf(f3,"%d ",b);
}
}
else if(feof(f2))
{
if(a<=b){
fprintf(f3,"%d ",a);
fprintf(f3,"%d ",b);
}else{
fprintf(f3,"%d ",b);
fprintf(f3,"%d ",a);
}
while(!feof(f1)){
fscanf(f1,"%d",&a);
fprintf(f3,"%d ",a);
}
}
fclose(f1);
fclose(f2);
fclose(f3);
printf("已完成!\n");
}
#include "stdio.h"
#include "conio.h"
main()
{
FILE *fp;
fp=fopen("text1.txt","r");
char ch;
int totalnum =0;
int totalwords =0;
while(ch!=EOF)
{
ch=fgetc(fp);
if(((ch>='A')&&(ch<='Z'))||((ch>='a')&&(ch<='z')))
{
totalwords++;
}
else if((ch>='0')&&(ch<='9'))
{
totalnum++;
}
}
printf("totalwords : %d\n",totalwords);
printf("totalnum :%d\n",totalnum);
fclose(fp);
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LINE 1000
#define RMV "/* XXXXX */"
int main()
{
char sLine[MAX_LINE];
char *pPos;
freopen("exam.c","rb",stdin);
freopen("exam.out","wb",stdout);
while (gets(sLine))
{
while (pPos = strstr(sLine,RMV))
{
*pPos = '\0';
strcat(sLine,pPos+strlen(RMV));
}
puts(sLine);
}
return 0;
}
#include<stdio.h>
void main()
{
FILE *f1,*f2,*f3;
int a,b;
f1=fopen("a1.txt","r");
f2=fopen("a2.txt","r");
f3=fopen("a3.txt","w");
//a=getw(f1);
fscanf(f1,"%d",&a);
//b=getw(f2);
fscanf(f2,"%d",&b);
while(!feof(f1)&&!feof(f2)) //两个文件都没结束时,执行循环、比较
{
if(a<=b){
fprintf(f3,"%d ",a);
fscanf(f1,"%d",&a);
}else{
fprintf(f3,"%d ",b);
fscanf(f2,"%d",&b);
}
}
if(feof(f1)) //文件a1.txt结束时,把a2.txt中的数全部输入a3.txt
{
if(a<=b){
fprintf(f3,"%d ",a);
fprintf(f3,"%d ",b);
}else{
fprintf(f3,"%d ",b);
fprintf(f3,"%d ",a);
}
while(!feof(f2)){
fscanf(f2,"%d",&b);
fprintf(f3,"%d ",b);
}
}
else if(feof(f2))
{
if(a<=b){
fprintf(f3,"%d ",a);
fprintf(f3,"%d ",b);
}else{
fprintf(f3,"%d ",b);
fprintf(f3,"%d ",a);
}
while(!feof(f1)){
fscanf(f1,"%d",&a);
fprintf(f3,"%d ",a);
}
}
fclose(f1);
fclose(f2);
fclose(f3);
printf("已完成!\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询