求各位帮个忙,关于链表的有关问题

求各位帮个忙,关于链表的问题
刚学了C++基础的东西 老师让编程序测试, 给了道链表的题, 然后就开始看链表,写了个东西,怎么也出不来结果。

题目:请设计一个链表结构的程序。该程序提取文件中的英文单词, 统计每个单词出现的次数。统计结束后,用户可以查询某个单词出现的个数,以及出现个数为某次的单词有哪些。


我写的代码 ,初学,可能错误很多
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
class list
{
public:
char word[50];
int count;
  list *next;
};
int main()
{
list *head,*ptr,*delptr,*p;
char w[50],c;
int a=0;
head=ptr=NULL;
ifstream infile("f2.txt",ios::in);
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
while(!infile.eof())
{
infile>>c;
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c=='\''))
w[a++]=c;
else if(a>0)
{
w[a]='\0';
if(head==NULL)
{
strcpy(head->word,w);
head->count=1;
}
else
{
ptr=head;
while(ptr!=NULL)
{
if(strcmp(ptr->word,w)==0)
{
ptr->count++;
break;
}
delptr=ptr;
ptr=ptr->next;
}
if(ptr==NULL)
{
p=new list;
strcpy(p->word,w);
p->count=1;
p->next=delptr->next;
delptr->next=p;
}
}
}
a=0;
}
ptr=head;
int p;
int o;
void danci(list*);
void geshu(list*);
do
{
cout<<"查找某个单词出现的个数请按1,查找出现个数为某次的请按2:";
cin>>p;
switch(p)
{
case 1:danci(ptr);break;
case 2:geshu(ptr);break;
}
cout<<"是否继续进行操作,是请按1,否请按0:";
cin>>o;
}while(o==1);
infile.close();
delete head;
return 0;
}

void danci(list *ptr)

string q;
cout<<"请输入您要查找的单词:";
cin>>q;
while(ptr!=NULL)
{

if(ptr->word==q)
{
cout<<"您要查找的单词数量为:"<<ptr->count<<endl;
}
}
}


void geshu(list *ptr)
{
int nu;
cout<<"查找单词数量为n的单词,请输入n:";
cin>>nu;
cout<<"您要查找的单词为:";
while(ptr!=NULL)
{
if(ptr->count==nu)
{
cout<<ptr->word<<" ";
}
}
}

------解决方案--------------------
我瞧了哈,你的代码
list *head,*ptr,*delptr,*p;
head=ptr=NULL;
strcpy(head->word,w);
并没有为head分配空间初始化,这肯定是一个致命错误

没仔细看,代码没得一句注释,看起蛋疼....用F10,F11慢慢调试吧..