Z
zotkara
Hello. I need help correcting the following C source code.
/* coder.c */
/* Usage: coder [filename] [action]
[action]
D decrypt
C crypt
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TITLE "coder\nAbout: encrypts or decrypts file."
#define USAGE "Usage: coder [filename] [action]\n\t[action]\n\td\tDecrypt file\n\tc\tCrypt file"
#define FILE_ERROR -2
#define DECRYPT 'd'
void start(int argc,char argv[]);
int encode_character(int ch,int val);
int decode_character(int ch,int val);
typedef crypt
{
int rv; // Recovery value
int ch; // Channel
unsigned int ctr; // Counter
int val; // Encrypt value
char buffer[257]; // Buffer
FILE *fh; // File handle
}engine0={1,0,0,5};
int main(int argc,char *argv[])
{
start(argc,argv); // Start engine
}
void start(int argc,char argv[])
{
crypt *engine1=&engine0; // Turn on engine
if(argc!=3)
{
printf("%s\n%s\n",TITLE,USAGE);
}
/* Note that content of if(content) is case-sensitive */
else if(argv[2]==DECRYPT)
{
(engine1->fh)=fopen(argv[1],"r"); // Opens file
if((engine1->fh)<=0)
{
printf("\n\nError opening file...");
(engine1->rv)=FILE_ERROR;
}
}
}
EOF
The following is the error message output by GNU gcc compiler in Slackware
10.2 in bash.
error: syntax error before '{' token
coder.c:29: error: parse error before '}' token
coder.c:29: error: parse error before ',' token
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
docs@pyenos:~/work_and_play/c++_learn$ gcc coder.c -o coder
coder.c:22: error: syntax error before '{' token
coder.c:29: error: parse error before '}' token
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
coder.c:29: warning: data definition has no type or storage class
coder.c: In function `main':
coder.c:33: warning: passing arg 2 of `start' from incompatible pointer type
coder.c: In function `start':
coder.c:39: error: `crypt' undeclared (first use in this function)
coder.c:39: error: (Each undeclared identifier is reported only once
coder.c:39: error: for each function it appears in.)
coder.c:39: error: `engine1' undeclared (first use in this function)
coder.c:48: warning: passing arg 1 of `fopen' makes pointer from integer
EOF
Please help me correcting this code as I am a newbie. Thanks in advance.
Zot
/* coder.c */
/* Usage: coder [filename] [action]
[action]
D decrypt
C crypt
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TITLE "coder\nAbout: encrypts or decrypts file."
#define USAGE "Usage: coder [filename] [action]\n\t[action]\n\td\tDecrypt file\n\tc\tCrypt file"
#define FILE_ERROR -2
#define DECRYPT 'd'
void start(int argc,char argv[]);
int encode_character(int ch,int val);
int decode_character(int ch,int val);
typedef crypt
{
int rv; // Recovery value
int ch; // Channel
unsigned int ctr; // Counter
int val; // Encrypt value
char buffer[257]; // Buffer
FILE *fh; // File handle
}engine0={1,0,0,5};
int main(int argc,char *argv[])
{
start(argc,argv); // Start engine
}
void start(int argc,char argv[])
{
crypt *engine1=&engine0; // Turn on engine
if(argc!=3)
{
printf("%s\n%s\n",TITLE,USAGE);
}
/* Note that content of if(content) is case-sensitive */
else if(argv[2]==DECRYPT)
{
(engine1->fh)=fopen(argv[1],"r"); // Opens file
if((engine1->fh)<=0)
{
printf("\n\nError opening file...");
(engine1->rv)=FILE_ERROR;
}
}
}
EOF
The following is the error message output by GNU gcc compiler in Slackware
10.2 in bash.
error: syntax error before '{' token
coder.c:29: error: parse error before '}' token
coder.c:29: error: parse error before ',' token
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
docs@pyenos:~/work_and_play/c++_learn$ gcc coder.c -o coder
coder.c:22: error: syntax error before '{' token
coder.c:29: error: parse error before '}' token
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
coder.c:29: warning: excess elements in scalar initializer
coder.c:29: warning: (near initialization for `engine0')
coder.c:29: warning: data definition has no type or storage class
coder.c: In function `main':
coder.c:33: warning: passing arg 2 of `start' from incompatible pointer type
coder.c: In function `start':
coder.c:39: error: `crypt' undeclared (first use in this function)
coder.c:39: error: (Each undeclared identifier is reported only once
coder.c:39: error: for each function it appears in.)
coder.c:39: error: `engine1' undeclared (first use in this function)
coder.c:48: warning: passing arg 1 of `fopen' makes pointer from integer
EOF
Please help me correcting this code as I am a newbie. Thanks in advance.
Zot