⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cxsj.txt

📁 学完C语言后的一个课程设计
💻 TXT
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define LENGTH sizeof(struct string)
struct string
{
 char word;
 struct string *next;
};
struct string * newy(struct string *head)   /*创建链表函数*/
{   char stringname[80];
 int j;
 int i;
 struct string *p,*p1;
 printf("\n input the new string:\n");
 gets(stringname);
 j=strlen(stringname);
 for(i=0;i<j;i++)
 {
  p=(struct string *)malloc(LENGTH);
 
  p->word=stringname[i];
  if(head==NULL)
  {head=p;
  p1=p;
  head->next=NULL;}
  else
  {p->next=p1->next;
  p1->next=p;
  p1=p;}}
 return(head);
}
struct string * times(struct string *head)  /*统计字母频率函数*/
{
 struct string *p2=head;
 struct string *head1=NULL,*p,*p1;
 int n=0;
    char b;
 printf("\n 输入要计算的字母:\n");
 scanf("%c",&b);
 while(p2!=NULL)
 {
 p=(struct string *)malloc(LENGTH);    /*开辟一个新的单元*/
 p->word=p2->word;
 if(head1==NULL)
 {head1=p;
 p1=p;
 head1->next=NULL;}
 else
 {p->next=p1->next;
 p1->next=p;
 p1=p;}
  if(p2->word==b)
  {
    n++;
   p2=p2->next;
  }
  else
   p2=p2->next;}
 printf("\n 结果为:\n");
 printf("%c   %d",b,n);
 return(head1);
}
struct string * find(struct string *head)  /*查找替换函数*/
{
 struct string *p3=head;
 struct string *p7=head;
 struct string *head1=NULL,*p,*p1;
 char c,k;
 printf("\n要查找的字母\n要替换的字母:\n");
 scanf("%c  %c",&c,&k);
 while(p3!=NULL)
 { p=(struct string *)malloc(LENGTH);
   p->word=p3->word;
   if(head1==NULL)
 {head1=p;
 p1=p;
 head1->next=NULL;}
 else
 {p->next=p1->next;
 p1->next=p;
 p1=p;}
  if(p3->word==c)
 {
   p3->word=k;
   p3=p3->next;}
  else
  p3=p3->next;
 }
 printf("结果为:\n");
 while(p7!=NULL)
  {printf("%c",p7->word);
  p7=p7->next;
  }
  return(head1);
  }
struct string * delet(struct string *head)   /*删除字母函数*/
{
 struct string *p6,*p,*p1;
 struct string *p4=head,*p5;
 struct string *head1=NULL;
 char e;
 printf("输入要删除的字母:\n");
 scanf("%c",&e);
 while(p4!=NULL)
 { p=(struct string*)malloc(LENGTH);
 p->word=p4->word;
 if(head1==NULL)
 {head1=p;
 p1=p;
 head1->next=NULL;}
 else
 {p->next=p1->next;
 p4->next=p;
 p1=p;}
  if(p4->word==e)
  {
   if(p4==head)
   {p5=p4->next;
   head=p5;
   p4=head;
   }
   else
   {p5->next=p4->next;
   p4=p4->next;
   }
  }
  else
  {p5=p4;
  p4=p4->next;
 }}
 p6=head;
 printf("结果为:\n");
 while(p6!=NULL)
  {
   printf("%c",p6->word);
   p6=p6->next;
  }
  return(head1);
}
 void main()   /*主函数*/
{
 struct string *head1;
 char ch;
 int flag=1;
 head1=NULL;
 head1=newy(head1);
 while(flag)
 {
  printf("\n Input 'F'or'f'计算频率,'C'or'c'查找并替换字母,'D'or'd'删除字母,other to exit:\n");
  ch=toupper(getchar());/*
  getchar();
  if(ch=='F')
  head1=times(head1);
  else if(ch=='C')
   head1=find(head1);
  else if(ch=='D')
   head1=delet(head1);
  else
   flag=0;
  if(flag==0)
  printf("再输入一遍并退出:\n");
  getchar();
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -