On Tue, Jan 23, 2001 at 11:43:39AM +0530, Binand Raj S. wrote:

>> But our problem is after running the binary with the required parameters it
>> is not giving us the desired output.
>
>That shouldn't be a gets() problem. How did you run the program and what
>was the desired o/p? The actual o/p?

See Binand. It is like this. We run the binary as follows :

----------------------------------------------------------------
[rajesh@dempomail rajesh]$ ./spce
 
 usage  - ./spce [options] start-column length ltrl1 ltrl2
                c    - for comparing
                s    - for substuting
                n    - output with record numbers
[rajesh@dempomail rajesh]$       
----------------------------------------------------------------

There is a text file say EIT0100.SRT which contains the following :

110001012606040100         1001-01-0008-ROYALNO001520000               501     E
110001012631060100         1001-01-0008-ROYALNO000380000               506     E
110001012640060100         1001-01-0008-ROYALNO000760000               501     E
110002012645060100         1001-01-0008-ROYALNO000190000               530     E

We run spce say to compare and put the output in text file 

./spce c 1 2 11 < EIT0100.SRT > mad 
[ This tells spce to compare starting from 1st column length 2 for the text 11
and put the result in file mad ]

If we run this the output file mad should be :

11
11
11
11

But the output is coming blank. The same thing works on SCO Unix. Logically
compiling the same C program on Linux should have worked isn't it. ?

Same thing happens for the other options, substitute(s) etc.

I am attaching spce.c as well as a sample text file. Both are small. (Total 5k).

Thanks.


Regards


-- 
Rajesh Fowkar
(Computer Programmer)
V. S. DEMPO & CO. LTD., PANAJI-GOA

Email ID : [EMAIL PROTECTED], [EMAIL PROTECTED]
Web Site : http://www.dempos.com
050001002341030100      -111001-01-0008-ROYALNO076000000013604000              E
110001012606040100         1001-01-0008-ROYALNO001520000               501     E
110001012631060100         1001-01-0008-ROYALNO000380000               506     E
110001012640060100         1001-01-0008-ROYALNO000760000               501     E
110002012645060100         1001-01-0008-ROYALNO000190000               530     E
110002012646060100         1001-01-0008-ROYALNO000760000               538     E
110002012653070100         1001-01-0008-ROYALNO001520000               501     E
110002012664070100         1001-01-0008-ROYALNO000190000               556     E
110002012679080100         1001-01-0008-ROYALNO000380000               506     E
110002012682080100         1001-01-0008-ROYALNO000380000               538     E
110002012683080100         1001-01-0008-ROYALNO000095000               513     E
110002012688100100         1001-01-0008-ROYALNO000380000               506     E
110002012689100100         1001-01-0008-ROYALNO001900000               501     E
110003012705110100         1001-01-0008-ROYALNO000095000               513     E
110003012723120100         1001-01-0008-ROYALNO000760000               530     E
110004012750130100         1001-01-0008-ROYALNO000760000               501     E
110004012766140100         1001-01-0008-ROYALNO000380000               513     E
110004012772150100         1001-01-0008-ROYALNO000760000               538     E
110004012788150100         1001-01-0008-ROYALNO001900000               501     E
110005012815180100         1001-01-0008-ROYALNO000760000               538     E
110005012828180100         1001-01-0008-ROYALNO000760000               530     E
110005012833180100         1001-01-0008-ROYALNO000380000               512     E
110005012850190100         1001-01-0008-ROYALNO000760000               538     E
110005012852190100         1001-01-0008-ROYALNO000380000               513     E
110006012858190100         1001-01-0008-ROYALNO000380000               518     E
110006012864190100         1001-01-0008-ROYALNO001900000               501     E
110006012884210100         1001-01-0008-ROYALNO000760000               538     E
110006012891220100         1001-01-0008-ROYALNO001140000               538     E
110006012903220100         1001-01-0008-ROYALNO000760000               501     E
110006012906220100         1001-01-0008-ROYALNO000380000               513     E
110007012923240100         1001-01-0008-ROYALNO000760000               538     E
110007012941250100         1001-01-0008-ROYALNO000190000               556     E
110007012943250100         1001-01-0008-ROYALNO000380000               530     E
110008012969270100         1001-01-0008-ROYALNO000760000               538     E
110008012990270100         1001-01-0008-ROYALNO001900000               501     E
110008013002280100         1001-01-0008-ROYALNO000190000               556     E
110009013028290100         1001-01-0008-ROYALNO000190000               306105  E
110009013038290100         1001-01-0008-ROYALNO000095000               513     E
050001002341030100      -111001-01-0010-ROYALNO024000000002400000              E
110001012625050100         1001-01-0010-ROYALNO000150000               513     E
110001012639060100         1001-01-0010-ROYALNO000600000               518     E
110002012645060100         1001-01-0010-ROYALNO000150000               530     E
110002012646060100         1001-01-0010-ROYALNO000600000               538     E
110002012656070100         1001-01-0010-ROYALNO000150000               513     E
110002012664070100         1001-01-0010-ROYALNO000450000               556     E
050002002443280100         1002-01-0000      NO000045000000441000              E
050002002444280100         1002-01-0000      NO000015000000147000              E
050002002454310100         1002-01-0000      NO000060000000588000              E

/* SPCE - program for ----

*/
#include <stdio.h> 
main (argc,argv)
 int argc ;
 char *argv[] ;
{ int i , l , num_flg , cmp_flg , sbs_flg , frm , length , to , cmp_sts ;
  int rl ,rn , c ;
  char argstr[5],argoptn ,cmpstr[50] , sbsstr[50] ,recbuf[512] ,outbuf[512];
  char *argkey ,*frm_ptr,*to_ptr;
  if ( argc < 5 || argc > 6 ) prntusg(argv[0]) ;


  strcpy(argstr,argv[1]);
  argkey = argstr ;
  num_flg = cmp_flg = sbs_flg = 0 ;
  for (l = 0 ; l < strlen(argv[1]) ; l++ ) /* for checking valid optns */
     { strncpy (&argoptn,argkey,1) ;
       argkey += 1 ;
       if (argoptn == 'n') num_flg = 1 ;
       else if (argoptn == 'c') cmp_flg = 1 ;
       else if (argoptn == 's') sbs_flg = 1 ;
       else prntusg(argv[0]) ;
     }

   if (cmp_flg != 1 && sbs_flg != 1 ) prntusg(argv[0]) ;
   
   frm = atoi(argv[2]) ;
   length = atoi(argv[3]) ;
   if ( (frm < 1 || frm > 512) || (length < 0 || length > 50) )
      prntusg(argv[0]) ;
  
   if (( cmp_flg == 1 && strlen(argv[4]) != length ) ||
      (cmp_flg == 1 && sbs_flg == 1 && argc != 6 )) prntusg(argv[0]) ;

   if ((cmp_flg != 1 || sbs_flg != 1 ) && argc != 5 ) prntusg(argv[0]);

   cmpstr[0]='\0' ;sbsstr[0]='\0';
   if (cmp_flg == 1)  strcpy(cmpstr,argv[4]) ;
   if (cmp_flg == 1 && sbs_flg == 1) strcpy(sbsstr,argv[5]) ;
    else if (sbs_flg == 1 ) strcpy(sbsstr,argv[4]) ;


  frm = frm - 1 ;
  to = frm + length ;
  rn = 0 ;
  while (gets(recbuf) != NULL )
   {  rl = strlen(recbuf) ;
      rn ++;
      for (l=0;l < 513 ;l++) {outbuf[l]='\0';}

      if ( rl > 512)
        {fprintf (stderr , "\n  %s - Program buffer fault " ,argv[0]) ;
         exit (1);
        }
      strncpy(outbuf,recbuf,frm);
      cmp_sts = 0 ;
      if (cmp_flg == 1)
        {
          frm_ptr = &recbuf[frm] ;
         cmp_sts = strncmp(frm_ptr,cmpstr,length);
        }
     
      if (cmp_sts == 0 )
      {
       if (sbs_flg == 1 && rl >= frm ) 
       {
        strcat(outbuf,sbsstr);
         to_ptr = &recbuf[to] ;
         strcat(outbuf,to_ptr);
         if  (strlen(outbuf) > 512 )
           { fprintf (stderr , "\n %s - Program buffer fault " , argv[0]);
             exit (1) ;
           }
       }
       else if (cmp_flg == 1) 
           { frm_ptr = &recbuf[frm] ;
              strcat(outbuf,frm_ptr) ;
           }
       }
       else if (sbs_flg == 1 )
           { frm_ptr = &recbuf[frm] ;
             strcat(outbuf,frm_ptr) ;
           } 

       if (cmp_sts == 0 || sbs_flg == 1 )
       { if ( num_flg == 1)
           { fprintf (stdout ,"%d :",rn);}
       puts(outbuf);
      }
      
   }      
      exit(0);
}

prntusg(argv0)
char *argv0 ;
{  fprintf (stderr  , "\n usage  - %s [options] start-column length ltrl1 ltrl2 ", 
argv0);
   fprintf (stderr  , "\n                c    - for comparing ");
   fprintf (stderr  , "\n                s    - for substuting ");
   fprintf (stderr  , "\n                n    - output with record numbers \n") ;
   exit (1);
}

----------------------------------------------
An alpha version of a web based tool to manage
your subscription with this mailing list is at
http://lists.linux-india.org/cgi-bin/mj_wwwusr

Reply via email to