473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

chunk

My compiler gives me a syntax error on line 13 and I don't see. Here's
the code.

#include <stdio.h>
int chunk (char *n1, char *n2, int bs, int nb);
main(){
int chunk (char *n1, char *n2, int bs, int nb)
{FILE *fp;
fp=fopen(n1,"rb");
fread(n1,bs,sizeof(nb),fp);
fclose(fp);
fp=fopen(n2,"wb");
fwrite(n2,bs,sizeof(nb),fp);
fclose(fp);}

I would think this fuction should be declared on a header and compile into
an object file and maybe even a lib file and linked to something using main.
But this still should work shouldn't it?

Bill
Feb 4 '08 #1
10 2355
In article <Exupj.6292$qI.4067@trnddc03>,
Bill Cunningham <no****@nspam.comwrote:
My compiler gives me a syntax error on line 13 and I don't see. Here's
the code.
>#include <stdio.h>
int chunk (char *n1, char *n2, int bs, int nb);
main(){
int chunk (char *n1, char *n2, int bs, int nb)
{FILE *fp;
fp=fopen(n1,"rb");
fread(n1,bs,sizeof(nb),fp);
fclose(fp);
fp=fopen(n2,"wb");
fwrite(n2,bs,sizeof(nb),fp);
fclose(fp);}
You are missing a }. You have an open { from the main() line,
and you have an open { from the int chunk line that is inside main.

Unless you are using gcc or another compiler with a similar extension,
it is not allowed to define nested functions, so it would not be valid
to have int chunk() { inside of the definition of main.

You must be using a C90 compiler, as otherwise you would not be able
to use the implicit int return result for your definition of main(),
and yet you do not return any value within the body of main.
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block
Feb 4 '08 #2
You are missing a }. You have an open { from the main() line,
and you have an open { from the int chunk line that is inside main.

Unless you are using gcc or another compiler with a similar extension,
it is not allowed to define nested functions, so it would not be valid
to have int chunk() { inside of the definition of main.

You must be using a C90 compiler, as otherwise you would not be able
to use the implicit int return result for your definition of main(),
and yet you do not return any value within the body of main.
Oh I see now. What I think I would want to do is declare the function in
a header like what is above main() then define it in its own c file and run
gcc -c on it to make an object file. I have gcc-3.4.6. What about the
sizeofs will they work? I am using int on my machine because size_t and int
are both 32 bit. Short is 16 bit on my machine while a char of couse is 8
bit. I just want to use this on my machine otherwise I would have used
size_t bs and size_t nb. But here-

fwrite(n2,bs,sizeof(nb),fp); /* DO I need sizeof for fwrite? and the same
question for fread. */

Bill
Feb 4 '08 #3
"Bill Cunningham" <no****@nspam.comwrites:
My compiler gives me a syntax error on line 13 and I don't see. Here's
the code.

#include <stdio.h>
int chunk (char *n1, char *n2, int bs, int nb);
main(){
int chunk (char *n1, char *n2, int bs, int nb)
{FILE *fp;
fp=fopen(n1,"rb");
fread(n1,bs,sizeof(nb),fp);
fclose(fp);
fp=fopen(n2,"wb");
fwrite(n2,bs,sizeof(nb),fp);
fclose(fp);}
[...]

You have mismatched braces, and you're trying to define a function
inside another function (C doesn't allow nested function definitions).

The way you arrange your source code makes this kind of error
difficult to see. You hide your opening and closing braces by putting
them next to other tokens with no whitespace. Since they define the
structure of your program, they should stand out.

Here's a reformatted version of your program; I've changed nothing but
the layout:

#include <stdio.h>

int chunk (char *n1, char *n2, int bs, int nb);

main()
{
int chunk (char *n1, char *n2, int bs, int nb)
{
FILE *fp;
fp = fopen(n1, "rb");
fread(n1, bs, sizeof(nb), fp);
fclose(fp);
fp = fopen(n2, "wb");
fwrite(n2, bs, sizeof(nb), fp);
fclose(fp);
}

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 4 '08 #4
Bill Cunningham wrote:
My compiler gives me a syntax error on line 13 and I don't see.
Neither do we, since you didn't bother to show us the diagnostic or
identify line 13. In any case, your code is dead much earlier, since
you attempt to use nested functions, which do not exist in C.

Here's what you need to do. _Outside_ of main, insert this code:
#include <stdio.h>
void /* fixed bogus 'int' */ chunk(char *n1, char *n2,
int bs, int nb)
{
FILE *fp;
fp = fopen(n1, "rb");
fread(n1, bs, sizeof(nb), fp);
fclose(fp);
fp = fopen(n2, "wb");
fwrite(n2, bs, sizeof(nb), fp);
fclose(fp);
}

Here's the code.

#include <stdio.h>
int chunk (char *n1, char *n2, int bs, int nb);
main(){
int chunk (char *n1, char *n2, int bs, int nb)
{FILE *fp;
fp=fopen(n1,"rb");
fread(n1,bs,sizeof(nb),fp);
fclose(fp);
fp=fopen(n2,"wb");
fwrite(n2,bs,sizeof(nb),fp);
fclose(fp);}

I would think this fuction should be declared on a header and compile into
an object file and maybe even a lib file and linked to something using main.
What in the world is that supposed to mean?
But this still should work shouldn't it?
No. Grossly illegal code is not guaranteed to work.

Feb 4 '08 #5
On Feb 4, 7:46 am, Martin Ambuhl <mamb...@earthlink.netwrote:
Bill Cunningham wrote:
My compiler gives me a syntax error on line 13 and I don't see.

Neither do we, since you didn't bother to show us the diagnostic or
identify line 13. In any case, your code is dead much earlier, since
you attempt to use nested functions, which do not exist in C.
Please try to be more polite.
Here's what you need to do. _Outside_ of main, insert this code:
Why do you suggest code that is not correct?
#include <stdio.h>

void /* fixed bogus 'int' */ chunk(char *n1, char *n2,
int bs, int nb)
{
FILE *fp;
fp = fopen(n1, "rb");
What if fopen returns NULL?
fread(n1, bs, sizeof(nb), fp);
its sizeof (nb), bs, not the other way around.

I am curious what happends when bs*sizeof(nb) what n1 points to.
You also don't check the return value of fread.
fclose(fp);
fp = fopen(n2, "wb");
What if fopen returns NULL?
fwrite(n2, bs, sizeof(nb), fp);
its sizeof (nb), bs, not the other way around.
I am curious what happends when bs*sizeof(nb) what n2 points to.
You also don't check the return value of fwrite.
fclose(fp);
What about the return value of fclose()? fclose could fail here.
}
Here's the code.
#include <stdio.h>
int chunk (char *n1, char *n2, int bs, int nb);
main(){
int chunk (char *n1, char *n2, int bs, int nb)
{FILE *fp;
fp=fopen(n1,"rb");
fread(n1,bs,sizeof(nb),fp);
fclose(fp);
fp=fopen(n2,"wb");
fwrite(n2,bs,sizeof(nb),fp);
fclose(fp);}
I would think this fuction should be declared on a header and compile into
an object file and maybe even a lib file and linked to something using main.

What in the world is that supposed to mean?
Please try to be more polite, especially when you critisize someone
elses code and then you post code that does not work.
But this still should work shouldn't it?

No. Grossly illegal code is not guaranteed to work.
Again, please try to be more polite, your code was not correct either.
Feb 4 '08 #6
Martin Ambuhl wrote:
Bill Cunningham wrote:
My compiler gives me a syntax error on line 13 and I don't see.

Neither do we, since you didn't bother to show us the diagnostic or
identify line 13. In any case, your code is dead much earlier, since
you attempt to use nested functions, which do not exist in C.
I gave Bill a lot of (in my opinion of course) good information on this
problem last time. He ignored everything except adding the blockcount
parameter. Unfortunately he didn't USE that parameter, but it is indeed
there.

That's pretty much it for me. I'm not going to spend time and effort
trying to help when he doesn't listen.


Brian
Feb 4 '08 #7
I gave Bill a lot of (in my opinion of course) good information on this
problem last time. He ignored everything except adding the blockcount
parameter. Unfortunately he didn't USE that parameter, but it is indeed
there.

That's pretty much it for me. I'm not going to spend time and effort
trying to help when he doesn't listen.
I appreciate your help Brian. Maybe some of what you said went over my
head. You did spend quite a bit of time on this but I think I've encounted
new problems with trying to code this especially in the fread, fwrite.

Thanks

Bill
Feb 4 '08 #8
On 4 Feb 2008 at 17:51, Default User wrote:
Martin Ambuhl wrote:
>Bill Cunningham wrote:
My compiler gives me a syntax error on line 13 and I don't see.

Neither do we, since you didn't bother to show us the diagnostic or
identify line 13. In any case, your code is dead much earlier, since
you attempt to use nested functions, which do not exist in C.

I gave Bill a lot of (in my opinion of course) good information on this
problem last time.
Wa ha ha.
That's pretty much it for me. I'm not going to spend time and effort
trying to help when he doesn't listen.
A real tragedy for Bill, I'm sure. I wouldn't trust the Loser's advice
on how to brush my teeth.

Feb 4 '08 #9
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalideloquently wrote:
....
>
Wa ha ha.
>That's pretty much it for me. I'm not going to spend time and effort
trying to help when he doesn't listen.

A real tragedy for Bill, I'm sure. I wouldn't trust the Loser's advice
on how to brush my teeth.
Good line!
Definitely a keeper.

Feb 4 '08 #10
Bill Cunningham wrote:
This function is supposed to do part of what dd in unix and linux
does. dd if=n1 of=n2 bs=2048 count=1
Write down what you think "dd in unix does" means. That lets us know
that you understand what that phrase means. I could write out what I
think you are trying to do, but it's far better if you do it.
bs is block size. nb is number of blocks, like count in dd. n1 is the
name of the file and n2 is the name of the chunk or block I want.
See, that last part makes no sense. I believe n2 is the output
filename. I don't even know what "name of the chunk or block" means. As
I said before, I strongly suggest that you start using descriptive
parameter and variable names. "n1" and "n2" are not descriptive.


Brian
Feb 4 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sandman | last post by:
Hi there! I am making a web page, and I want the user to be able to decide which part of the webpage ends up where, left or right side. So we have what I call "content" and "sidebar". As in a...
2
by: K.Simon | last post by:
Hello, I'm converting books from Docbook to HTML-chunk. For my needs it is necessary to append the list of figures at the end instead the beginning of the book as it is default in docbook. After...
40
by: Anony | last post by:
Hi All, I'm trying to chunk a long string SourceString into lines of LineLength using this code: Dim sReturn As String = "" Dim iPos As Integer = 0 Do Until iPos >= SourceString.Length -...
3
by: Eric Anderson Vianet SAO | last post by:
hello all When i tried ´pg_dump -v -f dump.dmp dtbtransporte´ I got the error: pg_dump: restoring data for table tbdmovimento pg_dump: dumping out the contents of table tbdmovimento ...
1
by: John | last post by:
Hi First of all apologies for posting so much code but this is rather involved and I am totally stumped. Basically I have a main form (Staff Batch SMS/E-Mail) which calls a function (SendSMS) in...
9
by: zerro | last post by:
Hello, I try to understand heap overflows (under Linux), but can not understand one thing with freeing memory allocated with malloc(). Here it comes: I have a program called 1.c: main() {...
7
by: rellaboyina | last post by:
Need to process an XML Chunk by Chunk..... I had an XML. It will consist of a number of similar type of tags and what I want to do is to process a certaing group of methods on each of these...
2
by: muslimak | last post by:
I have a perl script that throws an error "illegal division by zero" chunk 37. FYI, this script was the one that worked fine two days back. There is no change in the script. Can anyone tell...
3
by: rhicco75 | last post by:
Hi every one i am new with VB6.0 and i wanted to know if you know a site that will teach me on how to use the Get/Append Chunk... I need a step by step tutorial and also where can I find...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.