LOGO
首页 小说列表 排行榜 搜索

    C语言教程-第75页

  • 第1页
  • 上一页
  • 下一页

    温馨提醒:系统正在全面升级。您可以访问最新站点。谢谢!

      strncat(ch1,chtime,len);

      strcpy(chtime,"");

      strncat(chtime,ch1,len-1);

      gotoxy(13,7);printf(" ");}

      gotoxy(13,7);printf("%s",chtime);ch[0]=getch();

      if(ch[0]==9)

      goto mm;

      if(ch[0]==27)

      exit(1);

      }

      gotoxy(3,24);printf(" ");

      gotoxy(13,10);

      j=0;

      ch[0]=getch();

      while(ch[0]!='\r')

      { if (j<14)

      { strncat(chshop,ch,1);

      j++;}

      if(ch[0]==8)

      { len=strlen(chshop)-1;

      strcpy(ch1,"");

      j=j-2;

      strncat(ch1,chshop,len);

      strcpy(chshop,"");

      strncat(chshop,ch1,len-1);

      gotoxy(13,10);printf(" ");}

      gotoxy(13,10);printf("%s",chshop);ch[0]=getch();}

      gotoxy(13,13);

      j=0;

      ch[0]=getch();

      while(ch[0]!='\r')

      { if (j<6)

      { strncat(chmoney,ch,1);

      j++;}

      if(ch[0]==8)

      { len=strlen(chmoney)-1;

      strcpy(ch1,"");

      j=j-2;

      strncat(ch1,chmoney,len);

      strcpy(chmoney,"");

      strncat(chmoney,ch1,len-1);

      gotoxy(13,13);printf(" ");}

      gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();}

      if((strlen(chshop)==0)||(strlen(chmoney)==0))

      continue;

      if((fp=fopen("home.dat","a+"))!=NULL);

      fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney);

      fputc('\n',fp);

      fclose(fp);

      i++;

      gotoxy(41,5+i);

      printf("%10s %-14s %-6s",chtime,chshop,chmoney);

      }}}

      ==============================================================

      【程序96】

      题目:计算字符串中子串出现的次数

      1.程序分析:

      2.程序源代码:

      #include "string.h"

      #include "stdio.h"

      main()

      { char str1[20],str2[20],*p1,*p2;

      int sum=0;

      printf("please input two strings\n");

      scanf("%s%s",str1,str2);

      p1=str1;p2=str2;

      while(*p1!='\0')

      {

      if(*p1==*p2)

      {while(*p1==*p2&&*p2!='\0')

      {p1++;

      p2++;}

      }

      else

      p1++;

      if(*p2=='\0')

      sum++;

      p2=str2;

      }

      printf("%d",sum);

      getch();}

      ==============================================================

      【程序97】

      题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。

      1.程序分析:     

      2.程序源代码:

      #include "stdio.h"

      main()

      { FILE *fp;

      char ch,filename[10];

      scanf("%s",filename);

      if((fp=fopen(filename,"w"))==NULL)

      {printf("cannot open file\n");

      exit(0);}

      ch=getchar();

      ch=getchar();

      while(ch!='#')

      {fputc(ch,fp);putchar(ch);

      ch=getchar();

      }

      fclose(fp);

  • 第1页
  • 上一页
  • 下一页