Rekan,

Saya memodifikasi program C yang jalan di DOS untuk bisa jalan di Linux.
Listing program hasil modifikasi bisa di compile dan file executable terbentuk 
namun ketika dijalankan terjadi: Segmentation fault.

Mungkin ada yang bisa kasih petunjuk bagaimana memodifikasi listing program 
tersebut. Ini saya sertakan listing hasil modifikasinya. Program untuk 
memasukkan string dan format tanggal. 


/* Listing program GETP.C
   27 Desember 1994
modif. for Linux 29-11-2009
   ---------------------*/
#include<ncurses.h>
#include<stdlib.h>

//typedef enum boolean {FALSE,TRUE};

int get_str(int kol,int bar,char *string,
            int maxchar,int wr,int num,int up)
{
//  WINDOW *win;
  int x,y;
  int pos;
  int betul;
  pos=0;
  betul=0;
  union inkey
  {
    char ch[2];
    int i;
  }c;

//  textattr(wr);
  move(kol,bar);
//  x=wherex(); y=wherey();
  getyx(stdscr,y,x);
  move(x,y);
  for(;;)
  {
    c.i=getch();
    if(c.ch[0])
    {
     switch(c.ch[0])
      {
        case '\r': if(true==1) *string='\0';
                   return 1;
        case 8   : if(pos<=0)
                    break;
                   else
                   {
                     --x;
                     string--;
                     pos--;
                     move(x,y);
                     putchar(' ');
                   }
                    break;
        case 27  : return 0;
        default  : if(pos==0) betul=1;
                   if(pos>=maxchar)
                   break;
                   if(num==1) //string
                      {
                       if(!isascii(c.ch[0])) break;
                      }
                   if(num==2) //number
                      {
                      if(!isdigit(c.ch[0]) &&
                         c.ch[0]!='.' && c.ch[0]!=' ')
                      break;
                      }
                   if(up==TRUE) //upcase
                   { if(c.ch[0]>=97 && c.ch[0]<=122)
                      c.ch[0]=c.ch[0]-32;
                   }
                   *string=c.ch[0];
                   string++;
                   pos++;
                   x++;
                   printf("%c",c.ch[0]);
                   break;
      }
    }
    else
    {
      switch(c.ch[1])
      {
       case 75 : if(pos<=0)
                    break;
                   else
                   {
                     --x;
                     string--;
                     pos--;
                   }
                  break;

      case 77 : if(pos>=maxchar-1)
                    break;
                   else
                   {
                     ++x;
                     string++;
                     pos++;
                   }
                  break;
      case 72 : if(true==1) *string='\0';
                return 1;
      case 80 : if(true==1) *string='\0';
                return 1;
      }
    }
    move(x,y);
  }
}

int get_tgl(int kol,int bar,char *string,int wr)
{
//  WINDOW *win1;
  int x,y;
  int pos=0;

  union inkey
  {
    char ch[2];
    int i;
  }c;

//  textattr(wr);
  move(kol,bar);
//  x=wherex(); y=wherey();
  getyx(stdscr,y,x);
  move(x,y);
  for(;;)
  {
    c.i=getch();
    if(c.ch[0])
    {
      switch(c.ch[0])
      {
        case '\r': *string='\0';
                   return 1;
        case 8   : if(pos<=0)
                    break;
                   if(pos==6){pos--;--x;}
                   if(pos==3){pos--;--x;}
                   {
                     --x;
                     string--;
                     pos--;
                     move(x,y);
                     putchar(' ');
                   }
                    break;

        case 27  : return 0;
        default  : if(pos>=10)
                   break;
                   if(!isdigit(c.ch[0]))
                   break;
                   if(pos==1) {pos++;x++;}
                   if(pos==4) {pos++;x++;}
                   *string=c.ch[0];
                   string++;
                   pos++;
                   x++;

                   printf("%c",c.ch[0]);
                   break;
      }
    }
    else
    {
      switch(c.ch[1])
      {
       case 75 : if(pos<=0)
                    break;
                 if(pos==6){pos--;--x;}
                 if(pos==3){pos--;--x;}
                   {
                     --x;
                     string--;
                     pos--;
                   }
                  break;

      case 77 : if(pos>=9)
                    break;
                if(pos==1){pos++;++x;}
                if(pos==4){pos++;++x;}
                   {
                     x++;
                     string++;
                     pos++;
                   }
                  break;
      case 72 : //*string='\0';
                return 1;
      case 80 : //*string='\0';
                return 1;
      }
    }
    move(x,y);
  }
}

main()
{
  char *kata;
  initscr();cbreak();
  get_str(10,10,kata,10,10,10,1);
  getch();
  endwin();
}

Demikian TIA,

Salam,

Putra
-- 
---  L  I  N  U  X  ---
Registered User #146631
-----------------------


-- 
Berhenti langganan: linux-programming-unsubscr...@linux.or.id
Arsip dan info: http://linux.or.id/milis

Kirim email ke