I found the error immediately after posting this. The brace in one of the if statements was backwards.
I'm trying to compile a small program and can not find where the error is. It's in the main function of the following code:
Code:
#include "cp.h"
int
main(int argc, char *argv[])
{
int fdIn, fdOut;
char buff[MAXBUF];
if (argc != 3)
{
Usage(argv[0]);
exit(1);
}
if ( (fdIn = open(argv[1], O_RDONLY) ) == -1)
{
perror("open 1");
exit(1);
}
if ( (fdOut = open(argv[2], O_WRONLY) ) == -1)
{
perror("open 2");
exit(1);
}
while ( ReadLine(fdIn, buff) >= 0)
{
if ( (write(fdOut, buff, strlen(buff)) ) == -1)
{
perror("write");
exit(1);
{
}
return 0;
}
The other two files are the functions and header file:
Code:
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define MAXBUF 1024
void Usage(char *);
int ReadLine(int, char[MAXBUF]);
#include "cp.h"
void
Usage(char *fn)
{
printf("Usage: %s <filename 1> <filename 2>\n", fn);
}
int
ReadLine(int fd, char buff[MAXBUF])
{
char c;
int counter;
counter = 0;
do
{
c = fgetc(fd);
buff[counter++] = c;
}
while (counter < MAXBUF && c != '\n' && c != NULL && c != EOF);
buff[counter] = '\0';
if (c == NULL)
return 0;
else if (c == EOF)
return -1;
else
return counter;
}
cp.c: In function ‘main’:
cp.c:37:1: error: expected declaration or statement at end of input
}
^
cp.c:37:1: error: expected declaration or statement at end of input
I've looked this over till I'm blue in the face and can't find an error in main.
I'm uploading a tarball of the programs.