c语言中数组地址值怎么运算,c语言中如何把数组改正指针

满意答案

00e27ab806e4881f8254fe7ae8741834.png

viplizhi

2017.06.16

00e27ab806e4881f8254fe7ae8741834.png

采纳率:53%    等级:12

已帮助:7879人

// 测试结果:

// 请输入小写字母串:abcdef

// abcdef  [输出]

#include

#include

typedef struct pointer

{

char dat;

struct pointer *link;

} pointer;

pointer *readdata(pointer *head)

{ //读集合

//原代码char tmp[10];

//原代码char tmp2,tmp3;

char *tmp;         //tmp是指针

int n=10;          //动态数组的大小

pointer *p;        //p是新节点

pointer *current;  //current指向当前节点

int i=0;

//动态分配内存

tmp=(char *)malloc( n * sizeof(char) );

//原代码printf("input data ('0' for end):");

//原代码scanf("%s",&tmp);

printf("请输入小写字母串:");

scanf("%s",tmp);

while(*(tmp+i) != '\0')

{

if( (*(tmp+i)'z') )

{

printf("输入错误!必须为小写字母!ee\n");

return NULL;

}

i++;

}

i=0;

while(*(tmp+i) != '\0')

{

p=(pointer *)malloc(sizeof(struct pointer));

p->dat = *(tmp+i);

p->link = NULL;

if(head==NULL)

{

head=p;

current=head;  //current指向当前节点

}

else

{

current->link=p;

current=p;        //current指向当前节点

}

//原代码p->link=head->link;

//原代码head->link=p;

i++;

}

return head; //函数readdata()有返回值,返回链表头

}

void printData(pointer *head) //打印链表

{

pointer *p;

if(head==NULL)

{

printf("\n链表没有数据.\n");

return;

}

p=head;

while(p!=NULL)

{

printf("%c",p->dat);

p=p->link;

}

printf("\n");

}

int main()

{

pointer *head=NULL;

head=readdata(head); //创建链表

printData(head);      //打印链表

return 0;

}

00分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值