1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

error: expected â)â before â;â token

Discussion in 'C' started by reginaj, Aug 31, 2010.

  1. reginaj

    reginaj New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello Colleagues,

    I have not done C programming in years. I need some help in debugging a C program written by someone who has left our team. I have marked the lines having the error with "-->"

    Your kind assistance is very much appreciated. Here's the code:

    Code:
          1 #include 
          2 #include 
          3 #include 
          4 static char *StdKey     = "Transformation SaaS eNcRyPtIoN";
          5 static char *SourceStdDir       = "./";
          6 static char *TargetStdDir       = "/filer/";
          7 int
          8 main(argc,argv)
          9 int     argc;
         10 char    **argv;
         11 {
         12 char    *val;
         13 char    *buf;
         14 int     buflen = 2048;
         15 int     keylen;
         16 char    *SourceDir;
         17 char    *TargetDir;
         18 char    *InpFile;
         19 char    *OutFile;
         20 int     len;
         21 int     Inp;
         22 int     Out;
         23 int     In;
         24 char    *bufpos;
         25 char    *keypos;
         26 int     bufcnt;
         27 int     keycnt;
         28
         29         argc--;
         30         argv++;
         31
         32         val = getenv("SourceDir");
         33         if(val == (char *)NULL)
         34         {
         35                 SourceDir = SourceStdDir;
         36 #               ifdef debug
         37                         fprintf(stderr,"Using standard source directory         %s\n,SourceDir);
         38 #               endif
         39         }
         40         else
         41         {
         42                 len = strlen(val);
         43                 SourceDir = malloc((unsigned)(len + 1));
         44                 if(SourceDir == (char **)NULL)
         45                 {
         46                         fprintf(stderr,"allocation error (SourceDir)!\n"        );
         47                         exit(1);
         48                 }
         49                 else
         50                 {
         51                         strcpy(SourceDir,val);
         52 #                       ifdef debug
         53                                 fprintf(stderr,
         54                                 "Using environment SourceDir %s\n,Source        Dir);
         55 #                       endif
         56                 }
         57         }
         58
         59         val = getenv("TargetDir");
         60         if(val == (char *)NULL)
         61         {
         62                 TargetDir = TargetStdDir;
         63 #               ifdef debug
         64                         fprintf(stderr,"Using standard target directory         %s\n,TargetDir);
         65 #               endif
         66         }
         67         else
         68         {
         69                 len = strlen(val);
         70                 TargetDir = malloc((unsigned)(len + 1));
         71                 if(TargetDir == (char **)NULL)
         72                 {
         73                         fprintf(stderr,"allocation error (TargetDir)!\n"        );
         74                         exit(1);
         75                 }
         76                 else
         77                 {
         78                         strcpy(TargetDir,val);
         79 #                       ifdef debug
         80                                 fprintf(stderr,
         81                                 "Using environment target directory %s\n        ,TargetDir);
         82 #                       endif
         83                 }
         84         }
         85
         86         val = getenv("EncryptionKey");
         87         if(val == (char *)NULL)
         88         {
         89                 key = StdKey;
         90 #               ifdef debug
         91                         fprintf(stderr,"Using standard key %s\n,key);
         92 #               endif
         93         }
         94         else
         95         {
         96                 len = strlen(val);
         97                 key = malloc((unsigned)(len + 1));
         98                 if(key == (char **)NULL)
         99                 {
        100                         fprintf(stderr,"allocation error (key)!\n");
        101                         exit(1);
        102                 }
        103                 else
        104                 {
        105                         strcpy(key,val);
        106 #                       ifdef debug
        107                                 fprintf(stderr,
        108                                 "Using environment encryption key %s\n,k        ey);
        109 #                       endif
        110                 }
        111         }
        112         keylen = strlen(key);
        113
        114         buf = malloc((buflen));
        115         if(buf == (char **)NULL)
        116         {
        117                 fprintf(stderr,"allocation error (buffer)!\n");
        118                 exit(1);
        119         }
        120
        121         while (argc--)
        122         {
        123                 len = strlen(*argv) + strlen(SourceDir);
        124                 InpFile = malloc((unsigned)(len + 1));
        125                 if(InpFile == (char **)NULL)
        126                 {
        127                         fprintf(stderr,"allocation error (InpFile)!\n");
        128                         exit(1);
        129                 }
        130                 else
        131                 {
        132                         strcpy(InpFile,SourceDir);
        133                         strcat(InpFile,*argv);
        134 #                       ifdef debug
        135                                 fprintf(stderr,
        136                                 "InpFile = %s\n,InpFile);
        137 #                       endif
        138                 }
        139
        140                 len = strlen(*argv) + strlen(TargetDir);
        141                 OutFile = malloc((unsigned)(len + 1));
        142                 if(OutFile == (char **)NULL)
        143                 {
        144                         fprintf(stderr,"allocation error (OutFile)!\n");
        145                         exit(1);
        146                 }
        147                 else
        148                 {
        149                         strcpy(OutFile,TargetDir);
        150                         strcat(OutFile,*argv);
        151 #                       ifdef debug
        152                                 fprintf(stderr,
        153                                 "OutFile = %s\n,OutFile);
        154 #                       endif
        155                 }
        156
    -->    157                 Inp = open(InpFile;O_RDONLY);
        158                 if(Inp == -1)
        159                 {
        160                         fprintf(stderr,"file open error (InpFile)!\n");
        161                         exit(1);
        162                 }
        163                 Out = open(OutFile,O_WRONLY | O_CREAT | O_TRUNC);
        164                 if(Out == -1)
        165                 {
        166                         fprintf(stderr,"file open error (OutFile)!\n");
        167                         exit(1);
        168                 }
        169
        170                 keycnt=0;
        171                 keypos=key;
        172                 fprintf(stdout,
        173                         "Processing InpFile = %s ",InpFile);
        174
        175                 while (In = read(Inp,buf,buflen) > -1)
        176                 {
        177                         bufcnt=0;
        178                         bufpos=buf;
        179
        180                         while (bufcnt < In)
        181                         {
    -->    182                                 bufpos++ ^= keypos++;
        183                                 bufcnt++;
        184                                 keycnt++;
        185                                 if (keycnt = keylen)
        186                                 {
        187                                         keypos=key;
        188                                         keycnt = 0;
        189                                 }
        190                         }
    -->    191                         if (write(Out,buf;In) < In)
        192                         {
        193                                 fprintf(stderr,"file write error (OutFil        e)!\n");
        194                                 exit(1);
        195                         }
        196                         fprintf(stdout,
        197                                 ".");
        198                 }
        199
        200                 close(Inp);
        201                 close(Out);
        202                 free(InpFile);
        203                 free(OutFile);
        204                 fprintf(stdout,
        205                         "Processing completed to OutFile = %s\n",OutFile        );
        206         }
        207
        208
        209         return(0);
        210 }
        211
    
    
    Here are the error messages:

    pgpreplacement.c:157: error: expected â)â before â;â token
    pgpreplacement.c:157: error: too few arguments to function âopenâ
    pgpreplacement.c:182: error: invalid lvalue in assignment
    pgpreplacement.c:191: error: expected â)â before â;â token



    Yours truly,
    Regina
     

Share This Page