Click here to Skip to main content
15,917,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: voltage Pin
Yusuf23-Mar-09 3:11
Yusuf23-Mar-09 3:11 
GeneralRe: voltage Pin
CPallini23-Mar-09 3:17
mveCPallini23-Mar-09 3:17 
AnswerRe: voltage Pin
Iain Clarke, Warrior Programmer22-Mar-09 10:07
Iain Clarke, Warrior Programmer22-Mar-09 10:07 
QuestionHow to remove a underscore character from my string Pin
pandit8422-Mar-09 5:56
pandit8422-Mar-09 5:56 
AnswerRe: How to remove a underscore character from my string Pin
Yusuf22-Mar-09 6:07
Yusuf22-Mar-09 6:07 
AnswerRe: How to remove a underscore character from my string Pin
Rajesh R Subramanian22-Mar-09 6:08
professionalRajesh R Subramanian22-Mar-09 6:08 
AnswerRe: How to remove a underscore character from my string Pin
CPallini22-Mar-09 7:34
mveCPallini22-Mar-09 7:34 
QuestionAn 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Endomlic22-Mar-09 5:06
Endomlic22-Mar-09 5:06 
When I try to compile my code I get this error message:
@: gcc -o hw3 hw3.c
hw3.c: In function `main':
hw3.c:20: parse error before `char'
hw3.c:31: `buff' undeclared (first use in this function)
hw3.c:31: (Each undeclared identifier is reported only once
hw3.c:31: for each function it appears in.)

The error occurs because of my if statement.
When I place the if statement after the char declaration it works, also when I remove the if statement it compiles and works fine.

if(argc == 1){
printf("Error: hw3 <buffersize>");
return 1;
}

Also for a plain "if(){}" as well.

How do I get around this?

#include 
#include 
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
	//our file references and read and write counts
	int fileread, filewrite;
	ssize_t nread, nwrite;

	if(argc == 1){
		printf("Error: hw3 <buffersize>");
		return 1;
	}

	//our buffer size is determined by the user
	char buff[ (int)argv[2] ];

	// open 128kB file for reading
	// create if it doesn't exist copy.bmp for writing
	fileread = open("128kB.bmp", O_RDONLY);
	filewrite = creat("copy.bmp", O_WRONLY);

	//copy all of the contents of the file	
	while(1)
	{
		//read data from the input file and place in the buffer
		nread = read(fileread, buff, sizeof(buff) );

		//if no information left to read, exit while loop
		if (nread == 0) break;

		//write the data from the buffer into the output file
		nwrite = write(filewrite, buff, sizeof(buff) - 1 );
	}

	//close the files
	close(fileread);
	close(filewrite);

	return 0;
}</buffersize></stdio.h></fcntl.h>




I am using a putty terminal connected to a unix machine.
AnswerRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Rajesh R Subramanian22-Mar-09 5:18
professionalRajesh R Subramanian22-Mar-09 5:18 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Endomlic22-Mar-09 5:23
Endomlic22-Mar-09 5:23 
AnswerRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Rajesh R Subramanian22-Mar-09 5:32
professionalRajesh R Subramanian22-Mar-09 5:32 
AnswerRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 5:21
Eytukan22-Mar-09 5:21 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Rajesh R Subramanian22-Mar-09 5:28
professionalRajesh R Subramanian22-Mar-09 5:28 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 5:34
Eytukan22-Mar-09 5:34 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Endomlic22-Mar-09 5:36
Endomlic22-Mar-09 5:36 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 5:38
Eytukan22-Mar-09 5:38 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Endomlic22-Mar-09 5:41
Endomlic22-Mar-09 5:41 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 5:59
Eytukan22-Mar-09 5:59 
JokeRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Rajesh R Subramanian22-Mar-09 5:40
professionalRajesh R Subramanian22-Mar-09 5:40 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 5:46
Eytukan22-Mar-09 5:46 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Endomlic22-Mar-09 5:54
Endomlic22-Mar-09 5:54 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 6:02
Eytukan22-Mar-09 6:02 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
CPallini22-Mar-09 7:40
mveCPallini22-Mar-09 7:40 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
Eytukan22-Mar-09 8:27
Eytukan22-Mar-09 8:27 
GeneralRe: An 'If' statement before my char declaration is not allowing my program to compile......why? Pin
CPallini22-Mar-09 6:23
mveCPallini22-Mar-09 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.