#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Angry Please everybody fix for me this error


    I have a program use language C but when run program then had error. Please everybody can fix for me this error.
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    #include<dos.h>
    #define M 30
    #define N 30
    double s[N+2][M+1] , r , gz;
    int kgd,kgd2,blap,blap2,sb,cmin,x0,ss;
    int m,n,i,j,k,l,le,lc,tg,cs[N+2],nc[M+1];
    unsigned long far *t; long int t1,t2;
    char *s1,*s2;FILE *f1,*f2;
    int ktnguyen (double x);
    int cotquay();
    void biendoi();
    void inbang(int cuoi);
    int dhdoingau();
    int main(){
         t=(unsigned long far *)MK_FP(0,0X46C); t1=*t;
         printf("\nCo in trung hay hay khong 1/0?");
         scanf ("%d%*c",&tg);
          //Nhap du lieu
         printf ("\nVao ten tep so lieu:"); get(s1);
         f1=fopen(s1,"r");fscanf(f1,"%d%d%lf%d%d",&n,&m,&gz,&x0,&ss);
         for(i=0;i<=n;i++) 
              for(j=0;j<=m;j++){
                    fscanf(f1,"%lf",&r);
                    s[i][j]=r;         
              }
         for(i=0;i<=n;i++) fscanf(f1,"%d",&cs[i]);
         for(j=0;j<=m;j++) fscanf(f1,"%d",&nc[j]);
         fclose(f1);
         sb=1; blap =0;
         //in du lieu vua nhap de kiem tra
         printf ("\nn,m,ep,gz,x0,ss= %d %d %13.5lf %d %d",n,m,gz,x0,ss);
         if(tg==1){
                   printf("\nvao ten tep chua ket qua :"); gets(s2);
                   f2=fopen (s2,"w");
                   fprintf(f2,"\nn,m,ep,gz,x0,ss= %d %d %13.5lf %d %d",n,m,gz,x0,ss);
         }
         printf("\nBang 1, so lieu ban dau :");
         if(tg==1) fprintf(f2,"\nbang1, so lieu ban dau:");
         inbang(0);
         if(ss==1){
                   printf("\nBang 1, so lieu ban dau, l-chuan, chap nhan duoc");
                   if(tg==1) fprintf(f2,"Bang1, so lieu ban dau, l-chuan, chap nhan duoc");
                   lc=n; goto Lap1;
         }
         if(ss==2){
                   printf("\nBang1, so lieu ban dau, l-chuan, khong chap nhan duoc, chay ngay DHDN");
                   if(tg==1) fprintf(f2, "\nBang1, so lieu ban dau, l-chuan, khong chap nhan duoc, chay ngay DHDN");
                   goto L1;
         }
         //them rang buoc phu
         sb=1; cs[n+1]=n+1;;s[n+1][0]=gz;
         for(j=1;j<=m;j++) s[n+1][j]=1;
         printf("\nBang1, so lieu ban dau them rang buoc phu");
         inbang(1);
         l=n+1; // dong quay la dong cuoi cung
         //xac dinh cot quay
         cmin=1;
         for(j=2;j<=m;j++){
             for(i=0;i<=n;i++){
                  if(s[i][cmin]>s[i][j]){
                      cmin=j;
                      break;
                  }
                   if(s[i][cmin]<s[i][j]) break;
             }
         }
         printf("\nDong quay =%d, Cot quay=%, Phan tu quay =%13.5lf",l,cmin,s[l][cmin]);
         if(tg==1){
                   fprintf(f2,"\nDong quay =%d, Cot quay=%, Phan tu quay =%13.5lf",l,cmin,s[l][cmin]);
         }
         biendoi();sb++;
         printf("\nBang %d, l-chuan dau tien",sb);
         if(tg==1) fprintf(f2, "\n bang %d, l-chuan dau tien",sb);
         inbang(0);
         L1: kgd2 = dhdoingau();
         if(kgd2 ==1){
                 printf("\n Bai toan phu khong gai duoc, STOP");
                 if(tg==1) fprintf(f2,"\nBai toan phu khong giai duoc ,STOP");
                 getch();
                 return 0;
         }
         lc = n+1;
         //Tim xong bang l-chuan +chap nhan duoc, sang Buoc lap lon
         Lap1: blap= blap+1;
         printf("\n----------------------------------");
         printf("\n\n BUOC LAP LON THU %d:",blap);
         if(tg==1){
                   fprintf(f2,"\n----------------------------------");
                   fprintf(f2,"\n\n BUOC LAP LON THU %d:",blap);
         }
         //Kiem tra loi giai toi uu bai toan phu co nguyen khong
         le= -1;
         for(i=x0;i<=n;i++)
          if(ktnguyen(s[i][0]) == 0){
                               le=i;
                               break;
          }
         printf("\n Thanh phan le thuoc dong = %d", le);
         if ( tg==1) fprintf(f2,"\n Thanh phan le thuoc dong = %d", le);
         if( le =-1){
             printf("\nPHUONG AN TOI UU QHTT NGUYEN:");
             if(tg==1) fprintf(f2,"\nPHUONG AN TOI UU QHTT NGUYEN:");
             for(i=0;i<=n;i++)   printf("\nx[%2d] = %13.5lf",cs[i],s[i][0]);
             printf("\nso luong lat cat la: %d lat cat", blap-1);
             printf("\nSo bang don hinh da lap: %d bang", sb);
             if(tg==1){  for(i=0;i<=n;i++)
                 fprintf(f2,"nx[%2d] = %13.5lf",cs[i],s[i][0]);
                 fprintf(f2,"\nso luong lat cat la: %d lat cat", blap-1);
                 fprintf(f2,"\nSo bang don hinh da lap: %d bang", sb);
             }
             t=(unsigned long far*)MK_FP(0,0X46C);
             t2 = *t;
             printf("\nThoi gian chay chuong  trinh : %ld giay", (long int )((t2-t1/18.21)));
             if(tg==1) fprintf(f2,"\nThoi gian chay chuong  trinh : %ld giay",(long int)(t2-t1)/18.21);
             fclose (f2);
             getch();
             return 0;
         }
         //    Tao lat cat cuoi va ghi vao dong cuoi
         lc++;
         cs[n+1]=lc;
         for(j=0;j<=m;j++){
             if(ktnguyen(s[le][j]))   s[n+1][j]=0;
             else s[n+1][j] = -(s[le][j]-floor(s[le][j]));
         }
         printf("\nBang %d , sau khi them lat cat ", sb);
         if (tg==1) fprintf(f2,"\nbang %d , sau khi them lat cat", sb);
         inbang(1);
         //xac dinh dong quay va cot quay
         l= n+1;
         printf("\nDong quay = %d", l);
         if (tg==1) fprintf(f2,"\nDong quay =%d", l);
         cotquay();
         printf("\nCot quay = %d , Phan tu quay =%13.5lf",cmin,s[l][cmin]);
         if(tg==1) fprintf(f2,"\nCot quay = %d , Phan tu quay =%13.5lf",cmin,s[l][cmin]);
         //Bien doi bang don hinh
         biendoi();
         sb++;
         printf("\nBang %d, bang dau tien bai toan phu",sb);
         if(tg==1) fprintf(f2,"\nBang %d, bang dau tien bai toan phu",sb);
         inbang(0);
         kgd2 = dhdoingau();
         if(kgd2==1){  printf("\nBai toan phu khong giai duoc");
                       if(tg==1) fprintf(f2,"\nBai toan phu khong giai duoc, STOP");
                       getch();
                       return 0;
         }
         goto Lap1;
    }
    
    int ktnguyen(double x){
        long int h;
        double z; z= fabs(x); h=(int)(z+0.5);
        if(fabs(z-h)<=0.0001) return 1;
        else return 0;
    }
    int cotquay(){
      k=0;
      for(j=1;j<=m;j++)
           if(s[l][j]<-0.000001){k=j;break;}
      if(k==0)  return 1;
      cmin= k;
      for(j=k+1;j<=m;j++)
       if(s[l][j]<-0.000001){
           //so sanh cot cmin voi cot j
           for(i=0;i<=n;i++){
                  double t1,t2;
                  t1= s[i][cmin]/fabs(s[l][cmin]);
                  t2= s[i][j]/fabs(s[l][j]);
                  if(t1>t2){
                            cmin=j;
                            break;
                  }
                  
                  if(t1<t2)  break;
           }
       }
       return 0;
    }
    
    void biendoi(){
         for(j=0;j<=m;j++)
            if(j!=cmin){
                 for(i=0;i<=n;i++)
                     if(i!=l) s[i][j]= s[i][j] -(s[l][j]/s[l][cmin])*s[i][cmin];
                     s[l][j] =0;
            }
            for(i=0;i<=n;i++) if(i!=l) s[i][cmin]= -s[i][cmin]/s[l][cmin];
            s[l][cmin]=-1;
            nc[cmin]= cs[l];
    }
     void inbang(int cuoi){
          int n1;
          if(cuoi==1) n1= n+1;
          else n1=n;
          printf ("\nco so:");
          for(i=0;i<=n;i++)  printf("%d", cs[i]);printf("\n");
          printf("\nphi co so:");
          for(j=1;j<=m;j++)   printf("%d", nc[j]);printf("\n");
          for(i=0;i<=n;i++) {
               for(j=0;j<=m;j++)
                  printf("%10.5lf",s[i][j]);
                  printf("\n");
          }
          if (tg==1)  fprintf (f2,"\n co so");
          for(i=0;i<=n;i++)  fprintf(f2,"%d", cs[i]);fprintf(f2,"\n");
          fprintf(f2,"\nphi co so:");
          for(j=1;j<=m;j++)   fprintf(f2,"%d", nc[j]);fprintf(f2,"\n");
          for(i=0;i<=n;i++) {
               for(j=0;j<=m;j++)
                  fprintf(f2,"%10.5lf",s[i][j]);
                  fprintf(f2,"\n");
          }
          getch();
     }
     
     int dhdoingau(){
         blap2 =0;
         Lap2:blap2++;
         printf("\nBuoc lap don hinh doi ngau thu %d:",blap2);
         if(tg==1) fprintf(f2,"\nBuoc lap don hinh doi ngau thu %d:",blap2);
         l=-1;
         for(i=1;i<=n;i++) if(s[i][0]<0){l=i;break;}
         printf("\nDong quay %d",l);
         if(tg==1) fprintf(f2,"\nDong quay %d",l);
         if(l==-1){
                   printf("\nbang tren ung voi phuong an toi uu cua bai toan phu");     
                   if(tg==1) fprintf(f2,"\nbang tren ung voi phuong an toi uu cua bai toan phu"); 
                   return 0;
         }
         else{
              kgd=cotquay();
              if(kgd==1)  return 1;
              printf("\nCot quay =%d, Phan tu quay = %13.5lf", cmin,s[l][cmin]);
              if(tg==1) fprintf(f2,"\nCot quay =%d, Phan tu quay = %13.5lf", cmin,s[l][cmin]);
              biendoi();
              sb++;
              printf("\nBang %d, DHDN",sb);
              if(tg==1) fprintf(f2,"\nBang %d, DHDN",sb);
              inbang(0);
              goto Lap2;
         }
     }
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Well, since you won't tell us anything about what that error might be, I guess you are not interested in getting any help.

    Though it's nice that you used code tags. Thank you for that.

    When I compiled your code with MinGW gcc set to display all warnings, this is what I got:
    C:\otros\dcw>gcc -Wall biendoi.c conio.c
    biendoi.c:10: parse error before `*'
    biendoi.c:10: warning: type defaults to `int' in declaration of `t'
    biendoi.c:10: warning: data definition has no type or storage class
    biendoi.c: In function `main':
    biendoi.c:18: parse error before `far'
    biendoi.c:22: warning: implicit declaration of function `get'
    biendoi.c:34: warning: use of `l' length character with `f' type character
    biendoi.c:38: warning: use of `l' length character with `f' type character
    biendoi.c:70: warning: unknown conversion type character `,' in format
    biendoi.c:70: warning: use of `l' length character with `f' type character
    biendoi.c:70: warning: too many arguments for format
    biendoi.c:72: warning: unknown conversion type character `,' in format
    biendoi.c:72: warning: use of `l' length character with `f' type character
    biendoi.c:72: warning: too many arguments for format
    biendoi.c:103: warning: suggest parentheses around assignment used as truth value
    biendoi.c:106: warning: use of `l' length character with `f' type character
    biendoi.c:110: warning: use of `l' length character with `f' type character
    biendoi.c:114: parse error before `far'
    biendoi.c:117: warning: long int format, double arg (arg 3)
    biendoi.c:137: warning: use of `l' length character with `f' type character
    biendoi.c:138: warning: use of `l' length character with `f' type character
    biendoi.c: In function `inbang':
    biendoi.c:205: warning: use of `l' length character with `f' type character
    biendoi.c:214: warning: use of `l' length character with `f' type character
    biendoi.c: In function `dhdoingau':
    biendoi.c:237: warning: use of `l' length character with `f' type character
    biendoi.c:238: warning: use of `l' length character with `f' type character

    C:\otros\dcw>
    You need to correct all of those problems before even trying to run the program. If you don't, then your program will not do what you want it to do and it will give you unexpected results and have unexpected behavior.

    Never run a program that gives you warnings. Warnings are much more important than error messages are. Never ignore warnings! Always set your compiler to display all warnings and to do so most strictly.

    It is apparent that you are using an old 16-bit compiler, possibly Turbo C, which is more than 20 years old. My compiler is a 32-bit compiler, so it does not recognize far pointers; those warnings do not apply for you.

    Set your compiler to display all warnings and to do so strictly. If you are using Turbo C, I remember from 20 years ago that there is an option setting for that in the menus; look for it and set it. Read the warnings and correct your code to eliminate them. Do not try to run your program until you have eliminated all warnings by having corrected your code.

    And next time, when you are having a problem and are seeking help for it here, please describe that problem to us. Without that information, we cannot help you.
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    No shortage of sites where very similar code can be found
    Eg. http://dl.is.vnu.edu.vn/dspace/bitst...%20Gomory2.pdf

    The problem is, you copied the code from someone clueless about programming, rather than trying to learn and understand things for yourself.

    Simply by looking at the code, I can see that the program is screwed from the point where it calls gets(s1), because s1 is an uninitialised pointer.

    The code is horribly dependent on TurboC and DOS, which means if you tried to run it on any other OS/Compiler, you're stuck.

    It doesn't work is not a bug report.

    Finally, you don't give us an example input file, or your expected answers.

    IMO, the only way to fix this code is by pressing the delete key.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo