源码如下:
#include<stdio.h>
#include<stdlib.h>
struct node
{
char c;
struct node* next;
};
int main(int argc,char argv[])
{
int n;
scanf_s("%d", &n);
struct node* p_head, * p_tail, * p_new;
p_head = (struct node*)malloc(sizeof(struct node));
p_tail = p_head;
int j;
for (j = 0; j < n; j++)
{
p_new = (struct node*)malloc(sizeof(struct node));
scanf_s("%c", &(p_new->c));
p_tail->next = p_new;
p_tail = p_new;
}
struct node* p = p_head->next;
for (j = 0; j < n; j++)
{
printf("%c\n", p->c);
p = p->next;
}
return 0;
}
运行结果: