LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2017, 01:28 PM   #1
doughyi8u
Member
 
Registered: Apr 2010
Posts: 254

Rep: Reputation: 10
expected declaration compiler error


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.

Last edited by doughyi8u; 08-26-2017 at 01:30 PM. Reason: found error
 
Old 08-27-2017, 12:30 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Then it is solved now? Good.
 
Old 08-28-2017, 01:56 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Thanks for letting us know what you found.

If this issue is resolved please use the Thread Tools at top of first post to mark it solved.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C - Building a linux kernel module returns "error: expected declaration specifiers" netpumber Programming 5 01-22-2015 01:19 AM
expected declaration or statement at end of input eMCeee89 Programming 1 05-04-2009 02:54 AM
error: expected declaration or statement at end of input ? psernaalvarez Programming 3 02-16-2008 02:35 PM
Implicit Declaration Compiler Error Mistro116@yahoo.com Programming 1 12-11-2005 04:24 AM
g++ compiler error declaration does not declare anything Basiltp Programming 4 10-11-2004 11:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration