📄 91.html
字号:
gotoxy(13,7);printf(" ");}<br>
gotoxy(13,7);printf("%s",chtime);ch[0]=getch();<br>
if(ch[0]==9)<br>
goto mm;<br>
if(ch[0]==27)<br>
exit(1);<br>
}<br>
gotoxy(3,24);printf(" ");<br>
gotoxy(13,10);<br>
j=0;<br>
ch[0]=getch();<br>
while(ch[0]!='\r')<br>
{ if (j<14)<br>
{ strncat(chshop,ch,1);<br>
j++;}<br>
if(ch[0]==8)<br>
{ len=strlen(chshop)-1;<br>
strcpy(ch1,"");<br>
j=j-2;<br>
strncat(ch1,chshop,len);<br>
strcpy(chshop,"");<br>
strncat(chshop,ch1,len-1);<br>
gotoxy(13,10);printf(" ");}<br>
gotoxy(13,10);printf("%s",chshop);ch[0]=getch();}<br>
gotoxy(13,13);<br>
j=0;<br>
ch[0]=getch();<br>
while(ch[0]!='\r')<br>
{ if (j<6)<br>
{ strncat(chmoney,ch,1);<br>
j++;}<br>
if(ch[0]==8)<br>
{ len=strlen(chmoney)-1;<br>
strcpy(ch1,"");<br>
j=j-2;<br>
strncat(ch1,chmoney,len);<br>
strcpy(chmoney,"");<br>
strncat(chmoney,ch1,len-1);<br>
gotoxy(13,13);printf(" ");}<br>
gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();}<br>
if((strlen(chshop)==0)||(strlen(chmoney)==0))<br>
continue;<br>
if((fp=fopen("home.dat","a+"))!=NULL);<br>
fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney);<br>
fputc('\n',fp);<br>
fclose(fp);<br>
i++;<br>
gotoxy(41,5+i);<br>
printf("%10s %-14s %-6s",chtime,chshop,chmoney);<br>
}}} <br>
==============================================================<br>
【程序96】<br>
题目:计算字符串中子串出现的次数<br>
1.程序分析:<br>
2.程序源代码:<br>
#include "string.h"<br>
#include "stdio.h"<br>
main()<br>
{ char str1[20],str2[20],*p1,*p2;<br>
int sum=0;<br>
printf("please input two strings\n");<br>
scanf("%s%s",str1,str2);<br>
p1=str1;p2=str2;<br>
while(*p1!='\0')<br>
{<br>
if(*p1==*p2)<br>
{while(*p1==*p2&&*p2!='\0')<br>
{p1++;<br>
p2++;}<br>
}<br>
else<br>
p1++;<br>
if(*p2=='\0')<br>
sum++;<br>
p2=str2;<br>
}<br>
printf("%d",sum);<br>
getch();} <br>
==============================================================<br>
【程序97】<br>
题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。<br>
1.程序分析: <br>
2.程序源代码:<br>
#include "stdio.h"<br>
main()<br>
{ FILE *fp;<br>
char ch,filename[10];<br>
scanf("%s",filename);<br>
if((fp=fopen(filename,"w"))==NULL)<br>
{printf("cannot open file\n");<br>
exit(0);}<br>
ch=getchar();<br>
ch=getchar();<br>
while(ch!='#')<br>
{fputc(ch,fp);putchar(ch);<br>
ch=getchar();<br>
}<br>
fclose(fp);<br>
}<br>
==============================================================<br>
【程序98】<br>
题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。<br>
输入的字符串以!结束。 <br>
1.程序分析:<br>
2.程序源代码:<br>
#include "stdio.h"<br>
main()<br>
{FILE *fp;<br>
char str[100],filename[10];<br>
int i=0;<br>
if((fp=fopen("test","w"))==NULL)<br>
{ printf("cannot open the file\n");<br>
exit(0);}<br>
printf("please input a string:\n");<br>
gets(str);<br>
while(str[i]!='!')<br>
{ if(str[i]>='a'&&str[i]<='z')<br>
str[i]=str[i]-32;<br>
fputc(str[i],fp);<br>
i++;}<br>
fclose(fp);<br>
fp=fopen("test","r");<br>
fgets(str,strlen(str)+1,fp);<br>
printf("%s\n",str);<br>
fclose(fp);<br>
}<br>
==============================================================<br>
【程序99】<br>
题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), <br>
输出到一个新文件C中。<br>
1.程序分析:<br>
2.程序源代码:<br>
#include "stdio.h"<br>
main()<br>
{ FILE *fp;<br>
int i,j,n,ni;<br>
char c[160],t,ch;<br>
if((fp=fopen("A","r"))==NULL)<br>
{printf("file A cannot be opened\n");<br>
exit(0);}<br>
printf("\n A contents are :\n");<br>
for(i=0;(ch=fgetc(fp))!=EOF;i++)<br>
{c[i]=ch;<br>
putchar(c[i]);<br>
}<br>
fclose(fp);<br>
ni=i;<br>
if((fp=fopen("B","r"))==NULL)<br>
{printf("file B cannot be opened\n");<br>
exit(0);}<br>
printf("\n B contents are :\n");<br>
for(i=0;(ch=fgetc(fp))!=EOF;i++)<br>
{c[i]=ch;<br>
putchar(c[i]);<br>
}<br>
fclose(fp);<br>
n=i;<br>
for(i=0;i<n;i++)<br>
for(j=i+1;j<n;j++)<br>
if(c[i]>c[j])<br>
{t=c[i];c[i]=c[j];c[j]=t;}<br>
printf("\n C file is:\n");<br>
fp=fopen("C","w");<br>
for(i=0;i<n;i++)<br>
{ putc(c[i],fp);<br>
putchar(c[i]);<br>
}<br>
fclose(fp);<br>
}<br>
==============================================================<br>
【程序100】<br>
题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出<br>
平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。<br>
1.程序分析:<br>
2.程序源代码:<br>
#include "stdio.h"<br>
struct student<br>
{ char num[6];<br>
char name[8];<br>
int score[3];<br>
float avr;<br>
} stu[5];<br>
main()<br>
{int i,j,sum;<br>
FILE *fp;<br>
/*input*/<br>
for(i=0;i<5;i++)<br>
{ printf("\n please input No. %d score:\n",i);<br>
printf("stuNo:");<br>
scanf("%s",stu[i].num);<br>
printf("name:");<br>
scanf("%s",stu[i].name);<br>
sum=0;<br>
for(j=0;j<3;j++)<br>
{ printf("score %d.",j+1);<br>
scanf("%d",&stu[i].score[j]);<br>
sum+=stu[i].score[j];<br>
}<br>
stu[i].avr=sum/3.0;<br>
}<br>
fp=fopen("stud","w");<br>
for(i=0;i<5;i++)<br>
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)<br>
printf("file write error\n");<br>
fclose(fp);<br>
}</p>
<p><br>
<br>
</p>
<br>
</td>
<td width="20%"> </td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -