PDA

View Full Version : اشکالزدایی برنامه



night_star
جمعه 26 خرداد 1385, 12:14 عصر
من در برنامه زیر با مشکل برخورد کردم و اینه که 5 ارور داره و من نمی تونم اروریابی کنم کسی می تونه کمکم بکنه یا نه؟

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define max 100
struct addr{
char name[10];
char street[15];
char city;
char state[3];
unsingned long int zip;
}addr_info[max];
void init_list(void),enter(void);
void delet(void),list(void);
int menu_select(void),find_free(void);
main(void){
char choice,ch;
init_list();
for( ; ; ){
choice=menu_select();
switch(choice)
{
case 1:{
enter();
break;}
case 2: {
delet();
break; }
case 3:
list();
break;
case 4:
exit(0);
}
}

void init_list(void)
{
register int t;
for(t=1;t<max;++t)
addr_info[t].name[0]='\0' ;
}
menu_select(void)
{
char s[10];
int c;
clrscr();
gotoxy(29,6);
printf("1 )<<Enter A Name>>");
gotoxy(29,8);
printf("2 )<<Delete A name>>");
gotoxy(29,10);
printf("3 )<<list the file>>");
gotoxy(29,12);
printf("4 )<< quit >>");
do {
gotoxy(24,15);
printf("pleaes enter your choice(1-4):");
gets(s);
c=atoi(s);
}while(c<0 || c>4);
return (c);
}
void enter (void)
{
int slot;
char s[80];
slot=find_free();
if(slot=-1)
{
printf("\n list full");
return ;
}
gotoxy(5,7);
printf("enter name:");
gets(addr_info[slot].name);

gotoxy(40,17);
printf("enter street:");
gets(addr_info[slot].street);

gotoxy(5,19);
printf("enter city:");
gets(addr_info[slot].city);

gotoxy(40,19);
printf("enter state:");
gets(addr_info[slot].state);

gotoxy(22,21);
printf("enter zip:");
gets(s);

addr_info[slot].zip=strtoul(s,'\0',10);
}
find_free(void)
{
register int t;
for(t=0;addr_info[t].name && t<max ; ++t);
if (t==max)
return -1;
return t;
}
void delet(void)
{
int slot;
gotoxy(28,19);
printf("enter record #(0-99):");
scanf("%d",&slot);
if(slot>=0 && slot<max)
addr_info[slot].name[0]='\0';
}
void list(void)
{
register int t;
int r=0;
char ch;
clrscr();
gotoxy(25,2);
printf("<< all information in");
printf("list are:>>");
gotoxy(13,3);
printf("*************************");
printf("*********************");
printf("*************************");
gotoxy(10,4);
printf(" name street");
printf(" city ");
printf("state zip");
printf(" ");
gotoxy(10,5);
printf(" ______ ________");
printf(" _____ ");
printf("______ _____");
printf(" ");
for (t=0 ; t<max ;++t)
{
if (addr_info[t].name[0])
{
gotoxy(14,6+r);
printf("%s",addr_info[t].name);
gotoxy(26,6+r);
printf("%s",addr_info[t].street);
gotoxy(40,6+r);
printf("%s",addr_info[t].city);
gotoxy(54,6+r);
printf("%s",addr_info[t].state);
gotoxy(70,6+r);
printf("%1u",addr_info[t].zip);
r++;
}
}
gotoxy(13,6+r);
printf("**************************");
printf("****************************");
printf("**************************");
gotoxy(27,7+r);
printf("press any key to continue");
ch=getch();
}

//