ورود

View Full Version : باگ گرفتن و رفع اشکال کد



pooria_googooli
چهارشنبه 30 دی 1388, 23:26 عصر
دوستان من این برنامه دفترچه تلفن رو نوشتم. حالا میخوام اگه میشه مشکلشو رفع کنید. چون تو سرچش گیر میکنه. و باگیم اگه دید بگید. در ضمن برا نمایش به ترتیب حروف الفبا باید چه کنم؟ و یه موضوع دیگه اینه که شماره هارو بر اساس کد شهر که سه رقم اولش هستش مرتب کنه. در اون زمینم اگه میشه راهنماییم کنید. با تشکر از اساتید محترم.

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
void enter(int[],char[],char[],int i);
int main()
{
clrscr();
int a,h;
int i=1;
char tel[10][10];
char search[90];
char name[10][90];
char family[10][90];
char address[10][90];
Lable:
clrscr();
cout<<"1-Add new number\n2-Search\n3-delet\n";
cout<<"Enter a number you want\n";
scanf("%d",&a);
clrscr();
switch(a)
{
case 1 :
cout<<"\n Enter the name: ";
scanf("%s", name[i]);
cout<<"\n Enter the family: ";
scanf("%s", family[i]);
cout<<"\n Enter the tel number: ";
scanf("%s", &tel[i]);
cout<<"\n Enter the enter the addres: ";
scanf("%s", address[i]);
i++;
clrscr();
goto Lable;
case 2:
cout<<"1-by name"<<"\n2-by address"<<endl;
int q;
cin>>q;
if(a=2)
{
cout<<"enter the address :";
scanf("%s",search);
char *pos;char s1[90],s2[90];
for(int j=1;j<=10;j++)
{
strcpy(s1,address[j]);
strcpy(s2,search);
pos = strstr(s1,s2);
if(pos!=NULL)
{
h=j;
break;
}

}
cout<<tel[h]<<"\n"<<name[h]<<"\n"<<family[h]<<"\n"<<address[h];
clrscr();
goto Lable;
}
if(a=2)
{
cout<<"enter the name :";
scanf("%s",search);
char *pos;char s1[90],s2[90];
for(int j=1;j<=10;j++)
{
strcpy(s1,address[j]);
strcpy(s2,search);
pos = strstr(s1,s2);
if(pos!=NULL)
{
h=j;
break;
}

}
cout<<tel[h]<<"\n"<<name[h]<<"\n"<<family[h]<<"\n"<<address[h];
clrscr();
goto Lable;

}
case 3:
int rn,check=0;
char ch;
cout<<"which book do you want to remove?"<<endl;
while(check==0)
{
check=1;
cin>>rn;
if(rn>i)
{
cout<<"we havn't this number.pleas inter coorect number"<<endl;
check=0;
}
}
cout<<"name is : "<<name[rn-1]<<endl<<"Family is : "<<family[rn-1]<<endl<<"Tel is : "<<tel[rn-1]<<"Address is : "<<address[rn-1]<<endl;
cout<<"are you sure too remove this number?y/n";
cin>>ch;
if(ch=='y')
{
for(int l=rn;l<i;l++)
{
strcpy(name[rn-1],name[rn]);
strcpy(family[rn-1],family[rn]);
strcpy(tel[rn-1],tel[rn]);
strcpy(address[rn-1],address[rn]);
}
l--;
}
clrscr();
goto Lable;
}


getch();
return 0;
}

pooria_googooli
جمعه 02 بهمن 1388, 00:20 صبح
استید محترم اگه میشه کمکم کنید. به خدا من تازه کارم..

mortezamsp
جمعه 02 بهمن 1388, 18:54 عصر
فکرکنم تو scanf ها باید حتما از & استفاده کنی ولی فقط تو یکیش این کار رو کردی .

بعدشم برنامت چرا اینطوریه :

label :
scanf()
...
switch(){ case x : ... goto label ... }

اینطوریش کن :

while ( ! exit )
{ scanf()
...
switch () {
case x : ... break ;
case y : ... exit=1 ;
}
}

pooria_googooli
جمعه 02 بهمن 1388, 20:09 عصر
ممنون دوست عزیز. میشه در مورد مرتب سازی بر اساس حروف الفبا و کد شهرها برام توضیح بدی؟