Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update 27.c #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions 经典示例/027.字符替换/27.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX 50
/* ����repʵ�ֶ�s�г��ֵ�s1�е��ַ��滻Ϊs2����Ӧ���ַ� */
/* 函数rep实现对s中出现的s1中的字符替换为s2中相应的字符 */
rep(char *s,char *s1,char *s2)
{
char *p;

for(;*s;s++)/*˳������ַ���s�е�ÿ���ַ�*/
for(;*s;s++)/*顺序访问字符串s中的每个字符*/
{
for(p=s1;*p&&*p!=*s;p++);/*��鵱ǰ�ַ��Ƿ����ַ���s1�г���*/
if(*p)*s=*(p-s1+s2);/*��ǰ�ַ����ַ���s1�г��֣����ַ���s2�еĶ�Ӧ�ַ�����s�е��ַ�*/
for(p=s1;*p&&*p!=*s;p++);/*检查当前字符是否在字符串s1中出现*/
if(*p)*s=*(p-s1+s2);/*当前字符在字符串s1中出现,用字符串s2中的对应字符代替s中的字符*/
}
}
main( )/*ʾ�����*/
main( )/*示意程序*/
{
char s[MAX];/*="ABCABC";*/
char s1[MAX],s2[MAX];
clrscr();
system("clear") ;
puts("Please input the string for s:");
scanf("%s",s);
puts("Please input the string for s1:");
Expand All @@ -29,4 +30,4 @@ rep(char *s,char *s1,char *s2)
puts("\n Press any key to quit...");
getch();
}