PDA

View Full Version : سوال: مشكل اين برنامه چيه؟



Najva1989
چهارشنبه 09 دی 1388, 20:00 عصر
اين برنامه يه سري لغات رو به عناون فرهنگ لغت داخل يه درخت bst مي كنه و بعد يه متن رو گرفته و لغاتي رو كه داخل فرهنگ لغت نيستند رو مشخص مي كنه

حالا من هر كاري مي كنم ++c ارور مي ده

مشكل كجاست؟؟؟:گریه:


#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
struct node
{
char info[20];
node *left;
node *right;
}

node *insert(node *p,char x[20])
{
if (p==null)
{
p=new node;
p->info=x;
p->left= p->right =null;
}
else
{
node *help=p;
while(help!=null)
{
if(x > help->info)
{
if(help->right!=null)
help=help->right;
else
{
node *help1 = help->right;
help1=new node;
help1->info=x;
help1->left = help1->right = null;
}
}
else
{
if(help->left!=null)
help=help->left;
else
{
node *help1 = help->left;
help1=new node;
help1->info=x;
help1->left = help1->right = null;
}
}
}
}
return(p);
}

void comp(node*p,char x[20])
{
node *help=p;
while(help!=null)
{
if(strcmp(x,help->info)>0)
help=help->right;
else if (strcmp(x,help->info)<0)
help=help->left;
else
cout<<"word is in the dictionary.\n";
}
if(help=p && !strcmp(x,help->info))
cout<<"word isn't in the dictionary.\n";
}

main()
{
int i,j;
char x[20];f[20];s[100];
node first=null;
cout<<"enter the number of word for dictionary.\n";
cin>>n;
cout<<"enterthe word of dictionary.\n";
while(n-->0)
{
gets(f);
insert(first,f[20]);
}
cout<<"enter your text\n";
gets(s);
for (i=0;s[i];i++)
{
if (s[i]==" ")
{
j=0;
while (s[i]!=" ")
{
x[j]=s[i];
j++;
}
comp(first,x[20]);
}
}
getch();
}

mortezamsp
چهارشنبه 09 دی 1388, 20:21 عصر
اول اینکه NULL با حرف بزرگ بنویس .
دوم : آخر تعریف استراکت ; بذار .
سوم : برای کپی رشته از strcpy(,); استفاده کن .
چهار : x[20];f[20];s[100]; باید بینشون , بذاری نه ;
پنج : node first=NULL; فقط اشاره گر NULL میشه .
شش : باید اینطوری صدا بزنی : insert(first,f)
هفت : if (s[i]==" ") کاراکتر با '' نمایش داده میشه .
هشت : main باید return کنه چون int هست .


اینا غلط های املایی بودن .


#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
struct node
{
char info[20];
node *left;
node *right;
};
node* insert(node *p,char x[20])
{
if (p==NULL)
{
p=new node;
strcpy(p->info,x);
p->left= p->right =NULL;
}
else
{
node *help=p;
while(help!=NULL)
{
if(x > help->info)
{
if(help->right!=NULL)
help=help->right;
else
{
node *help1 = help->right;
help1=new node;
strcpy(help1->info,x);
help1->left = help1->right = NULL;
}
}
else
{
if(help->left!=NULL)
help=help->left;
else
{
node *help1 = help->left;
help1=new node;
strcpy(help1->info,x);
help1->left = help1->right = NULL;
}
}
}
}
return(p);
}
void comp(node*p,char x[20])
{
node *help=p;
while(help!=NULL)
{
if(strcmp(x,help->info)>0)
help=help->right;
else if (strcmp(x,help->info)<0)
help=help->left;
else
cout<<"word is in the dictionary.\n";
}
if(help==p && !strcmp(x,help->info))
cout<<"word isn't in the dictionary.\n";
}
main()
{
int i,j;
char x[20],f[20],s[100];
node *first=new node ;
cout<<"enter the number of word for dictionary.\n";
int n;
cin>>n;
cout<<"enterthe word of dictionary.\n";
while(n-->0)
{
gets(f);
insert(first,f);
}
cout<<"enter your text\n";
gets(s);
for (i=0;s[i];i++)
{
if (s[i]==' ')
{
j=0;
while (s[i]!=' ')
{
x[j]=s[i];
j++;
}
comp(first,x);
}
}
getch();
return 0 ;
}

Najva1989
چهارشنبه 09 دی 1388, 20:28 عصر
خيلي ممنونم -{{@

Najva1989
چهارشنبه 09 دی 1388, 20:37 عصر
راستي ببخشيد چرا وقتي برنامه اجرا مي كنم نمي تونم لغات رو وارد كنم
يعني وقتي بعد از اينكه تعداد لغات رو زدم و بعد از اينتر يه كلمه رو وارد كردم اگه اينتر بزنم ديگه كار نمي كنه؟؟؟؟؟؟؟؟