题一:
#include
#include
main()
{
FILE *file1,*file2;
char alp;
if((file1=fopen("text.txt","r"))==NULL||(file2=fopen("result.txt","w"))==NULL)
printf("文件打开失败");
else{
fscanf(file1,"%c",&alp);
while(!feof(file1)){
if(alp>='a'&&alp<='z')
alp=toupper(alp);
fprintf(file2,"%c",alp);
fscanf(file1,"%c",&alp);
}
}
fclose(file1);
fclose(file2);
return 0;
}
题二:
#include
main()
{
FILE *file1;
char alp,former_a='0';
int count_a=0,count_num=0,count_char=0,count_word=0;
if((file1=fopen("text.txt","r"))==NULL)
printf("文件打开失败");
else{
fscanf(file1,"%c",&alp);
while(!feof(file1)){
if((alp>='a'&&alp<='z')||(alp>='A'&&alp<='Z'))
count_a++;
else if(alp>='0'&&alp<='9')
count_num++;
else if((former_a>='a'&&former_a<='z')||(former_a>='A'&&former_a<='Z'))
count_word++;
former_a=alp;
fscanf(file1,"%c",&alp);
}
count_char=count_a+count_num;
}
printf("文本中字母个数为:%d\n文本中数字个数为:%d\n",count_a,count_num);
printf("文本中所有字符个数为:%d\n文本中单词个数为:%d\n",count_char,count_word);
fclose(file1);
return 0;
}
题三:
#include
#include
struct comp_num{
int con;
int vir;
struct comp_num *next;};
typedef struct comp_num COMPNUM;
typedef COMPNUM * COMPPTR;
void LlTraverse(int*,int*,COMPPTR);
main()
{
COMPPTR head=malloc(sizeof(COMPNUM));
COMPPTR current,newptr;
int counter,con_part,vir_part,con_sum=0,vir_sum=0;
char a;
printf("请输入十个复数(a+bi):\n");
current=head;
for(counter=0;counter<10;counter++)
{
scanf("%d%c%di",&con_part,&a,&vir_part);
newptr=(COMPPTR)malloc(sizeof(COMPNUM));
newptr->con=con_part;
newptr->vir=vir_part;
newptr->next=NULL;
current->next=newptr;
current=newptr;
}
printf("这10个复数的和为:\n");
LlTraverse(&con_sum,&vir_sum,head->next);
if(vir_sum==0)
printf("%d+%di",con_sum,vir_sum);
else
printf("%d",con_sum);
return 0;
}
void LlTraverse(int *sum_c,int *sum_v,COMPPTR com_ptr)
{
while(com_ptr){
*sum_c+=com_ptr->con;
*sum_v+=com_ptr->vir;
com_ptr=com_ptr->next;
}
}
我用VC6测的,没事儿啊。。。第二个注意test.txt要和源文件在一个目录底下,选“文件”->新建->C++源文件,然后保存成.c格式的,要还是不行看看这个吧,我是在不知道你这个为啥错了http://tieba.baidu.com/f?kz=170206384