c语言使用链表进行字符数组处理

使用链表  输入若干个字符数组,然后把数字去掉,再把$改为s,最后判断是否为回文  是的话yes否则no

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
int i,l;
char chushu(char *a,char *b);
char qian(char *a );
void huiwen(char *a);
int main(void)
{
    struct zhifu
    {
        int no;
        char chuan[80];
        char chuan2[80];
        char huiwen;
        struct zhifu *next;
    };
struct zhifu *first = NULL;
struct zhifu *ing = NULL;
struct zhifu *ing2=NULL;
struct zhifu *previous = NULL;
char test='\0';
for(;;)
{
    printf("\n你想继续输入字符数组吗(Y or N)?);
    scanf("%c",&test);
    if(tolower(test)=='n')
        break;
 
    ing=(struct zhifu*)malloc(sizeof(struct zhifu));
 
    if(first==NULL)
        first =ing;
 
    if(previous!=NULL)
        previous->next=ing;
    printf("\n这是第几次定义字符数组:");
    scanf("%d",&ing->no);
    printf("\n请定义第%d次字符数组:",ing->no);
    scanf("%s",ing->chuan);
	getchar();   
    ing->next=NULL;
    previous=ing;
 }

	for (ing = first; ing != NULL; ing = ing->next) {
		printf("%d: %s\n", ing->no, ing->chuan);
	}

ing=first;
while(ing!=NULL)
{
    char *p = ing->chuan;
    char *q = ing->chuan2;
	
   chushu(p,q);
   qian(q);
   huiwen(q);
   
    ing=ing->next;
   
}
	printf("\nafter modified:\n");
	for (ing = first; ing != NULL; ing = ing->next) {
		printf("%d: %s\n", ing->no, ing->chuan2);
	}
return 0;
}
char chushu(char *a,char *b)
{
	for( ; *b = *a; a++)     
        if( *a <'0' || *a >'9' ) 
			++b;
		return(*b);
}
char qian(char *a)
{
	for(;*a;a++)
	{	if(*a=='$')
			*a='s';
	i++;
	}
	return(*a);
}
void huiwen(char *a) 
{
    printf("%s\n", a); 
    char *p1 = a;
    char *p2 = (a+strlen(a)-1);
    while(p1 <  p2) {
        if(*(p1++) !=  *(p2--)){
            printf("NO\n");
            break;
        }   
        else  if(p1>=p2)
            printf("yes\n");
    }   
}



 


 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值