#include <stdio.h>
#include <stdlib.h>
struct s_list
{
char c ;
struct s_list *next;
};
void creat_list(struct s_list **headp)
{
char ch;
struct s_list * loc_head = NULL,*tail;
if((ch = getchar()) == EOF);
else
{
loc_head = (struct s_list *)malloc(sizeof(struct s_list));
loc_head -> c = ch;
tail = loc_head;
while((ch = getchar()) != EOF)
{
tail -> next = (struct s_list *)malloc(sizeof(struct s_list));
tail = tail -> next;
tail -> c = ch;
}
tail -> next = NULL;
}
*headp = loc_head ;
}
void print_list(struct s_list *headp)
{
while(headp != NULL)
{
printf("%c",headp->c );
headp = headp -> next;
}
printf("\n\n");
}
void print_array(struct s_list *headp)
{
int i,tot;
struct s_list * p = headp;
char * ch;
for(tot = 1; p->next != NULL; tot++)
{
p = p->next;
}
p = headp;
ch = (char *)malloc(tot*sizeof(char));
for(i = 0 ; i < tot ;i++)
{
ch[i] = p->c;
p = p -> next;
}
ch[i] = '\0';
puts(ch);
}
int main()
{
struct s_list *head = NULL;
creat_list(&head);
print_list(head);
print_array(head);
return 0;
}
#job 59 超长字符串
最新推荐文章于 2024-03-18 17:59:28 发布