关于#链表#的问题,如何解决?

这是PTA上的两道题,是关于单链表的,我提交的答案虽然编译成功但结果却不对,我自己也看不出哪里有问题,所以在此请教。
一、链表创建
本题要求实现一个函数,建立一个链表,返回头指针(即头节点地址)
head是链表的头指针,链表上节点的定义如下:

struct node {char ch; struct node * next;}

链表上节点的数据成员ch按顺序赋值0 1 2 3 直到 n-1
函数接口定义:
在这里描述函数接口。

struct node *setlink(int n);

n 是节点个数,返回值是头指针。
裁判测试程序样例:

#include <stdio.h>
#include<stdlib.h>
struct node {int ch; struct node * next;};
int countnode(struct node * head);//此函数功能遍历链表,已定义
struct node *setlink(int N);//在代码区定义此函数
int main() {
int i,N;
struct node *head;
scanf("%d",&N);
head=setlink(N);
printf("%d", countnode(head));
return 0;
} 
/* 请在这里填写答案 */

在这里给出一组输入。例如:

5

在这里给出相应的输出。例如:

10

这是我写的,虽然能编译,但答案是错的。

struct node *setlink(int n)
{
 
struct node *head, *p;
 
for(int i=0; i<n; i++)
{
p->next=i;
head->next=p;
p=p->next;
 
}
head->next=NULL;
return(head);
}

二、链表遍历
本题要求实现一个函数,从链表的头指针开始遍历整个链表,输出每个节点字符数据。

head是链表的头指针,链表上节点的定义如下:

struct node {char ch; struct node * next;}

函数接口:

void countnode(struct node *head);

head是链表头指针,函数显示链表中节点的ch成员中字符。

裁判测试程序:

#include <stdio.h>
#include<stdlib.h>
struct  node
{int ch;
struct node * next;} 
struct node *setlink(int  N);
 
void  countnode( struct  node * head);//在下面代码区定义此函数
 
int main()
{
int i,N;
struct node *head; 
scanf("%d",&N); 
 head=setlink(N);
 countnode(head);
  return 0;
}
 
/* 请在这里填写答案 */

输入样例:

5

输出样例:

abcde

这个的问题同上面一样。

void countnode(struct node *head)
{
struct node *pt=NULL;
pt=head->next;
if (pt == NULL) {
        printf("链表为空\n");
    }
while(pt!=NULL)
{
printf("%s", pt->next);
pt=pt->next;
}
}

struct node *setlink(int n)
{
    struct node *head, *p,*q;
    q=head=(struct node * )malloc(sizeof(struct node));
    head->next=NULL;
    for(int i=0; i<n; i++)
    {
        p=(struct node * )malloc(sizeof(struct node));
        p->ch=i;//
        p->next=NULL;
        q->next=p;
        q=p;
        //head->next=p;//head不能动
        //p=p->next;
    }
    //head->next=NULL;//此时head指向末尾了。
    return(head);
}




int countnode(struct node * head)
{
    struct node *p= head->next;
    while(p!=NULL)
    {
        printf("%d ",p->ch);
        p=p->next;
    }
}