برنامه 118 ساده

صفحه اصلی کارگروهها >> KARSHENASI  >> برنامه 118 ساده
سجاد  رحیمی

سجاد رحیمی

در کارگروه: KARSHENASI
تعداد ارسالي: 5
12 سال پیش در تاریخ: پنجشنبه, شهريور 16, 1391 11:32













برنامه 118 ساده : :


     #include
     #include
     #include
     #include
     void insert ();
     void search ();
     void del(void);
     void list(void);
    //******************************************************************//
  struct {
      char name[20];
      char lastname[20];
      char phone[15];
      char  address[50];
  }tel[100];
    //******************************************************************//
    void main()
     {
    int key;
    textcolor(12);
    textbackground(0);
    clrscr();
    printf("\n\n\t Inormation of Phone Number [118] !\n\n");
    printf("\n\n\t Welcome to my program !\n\n");
    printf("\n\n\t Program Writen By Hamid Abedi !\n\n");
    gotoxy(25,44);
    printf("Press any key to exit!");
    getch();
    textcolor(10);
    textbackground(8);
    clrscr();
    printf("\t      Please select and choice number !\n\n");
    printf("\t1.Insert In the list !\n\n");
    printf("\t2.Search In the list !\n\n");
    printf("\t3.View all of the list !\n\n");
    printf("\t4.Exit !\n\n=>");
    scanf("%d",&key);
    while(key!=4){


  switch(key){
   case 1:
    insert(); break;
   case 2:
    search();break;
   case 3:
    list();break;
   default:


    printf("\n\nBad command !!");
    }
    textcolor(12);
    textbackground(8);
    clrscr();
    printf("\r Press any key to select !\n\n");
    printf("\r 1.Insert In the list !\n\n");
    printf("\r 2.Search In the list !\n\n");
    printf("\r 3.View all of the list !\n\n");
    printf("\r 4.Exit !\n\n=>");
    scanf("%d",&key);
    }
    }
    //******************************************************************//
  void insert ()
  {
  int i=0;
  FILE *telph;
  textbackground(1);
  textcolor(14);
  clrscr();
  telph=fopen("tel.txt","a");


  if(telph==NULL){puts("Can not open the file");return;}
  puts("\n Enter 'end' to exit"
 "\n--------------------");
  printf("\nName :");
  scanf("%s",tel[i].name);


  while(strcmp(tel[i].name,"end"))
  {
  printf("\nLast Name :");
  scanf("%s",tel[i].lastname);
  printf("\nPhone Number :");
  scanf("%s",tel[i].phone);
  printf("\nAddress :");
  scanf("%s",tel[i].address);
  fwrite(&tel,sizeof tel[i],1,telph);
  printf("\nName :");
  i++;
  scanf("%s",tel[i].name);
  }
  fclose(telph);
  gotoxy(25,44);
  printf("Press any key to exit!");


  getch();
  }
    //*****************************************************************//
  void list(void)
  {
  int i=0;
  FILE *telph;
  textbackground(15);
  textcolor(1);
  clrscr();
  telph=fopen("tel.txt","a+t");
  if(telph==NULL){puts("Can not open the file");return;}
  puts("\n  LastName           Name            Number          Address"
  "\n-----------------------------------------------------------------------\n");
  while(fread(&tel,sizeof tel[i],1,telph))
  {
  printf("  %-15s   %-15s   %-15s    %-15s   \n",tel[i].lastname,tel[i].name,tel[i].phone,tel[i].address);
  }
  gotoxy(25,44);
  printf("Press any key to exit!");
  getch();
  }
  //*********************************************************************//
  void search (void)
  {
  int i=0;
  char nam[50];
  FILE *telph;
  textbackground(15);
  textcolor(4);
  clrscr();
  telph=fopen("tel.txt","a+t");
  if(telph==NULL){puts("Can not open the file");return;}
  printf("\n ** Welcom To Phone Information **\n");
  printf("\n ** Please enter the family for searching:>!\n");
  scanf("%s",nam);
  printf("\n Last Name        Name          Phone No           Address         ");
  printf("\n ححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححح");
  while(fread(&tel[i],sizeof tel[i],1,telph))
  {
  if(strcmp(tel[i].lastname,nam)==0)
  printf("\n %-10s      %-10s       %-10s       %-10s \n",tel[i].lastname,tel[i].name,tel[i].phone,tel[i].address);
  i++;
  }
  gotoxy(25,44);
  printf("Press any key to exit!");


  getch();
  }
  /*******************************************************************/




حذف ارسالي ويرايش ارسالي