[英] chunk

查看:56
本文介绍了块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的编译器在第13行给出了语法错误,我没有看到。这里是

代码。


#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);}


我认为这个函数应该在标题上声明并编译成

一个目标文件,甚至可能是一个lib文件,并链接到使用main的东西。

但这仍然应该工作不应该吗?


Bill

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

推荐答案

在文章< Exupj.6292
In article <Exupj.6292


qI.4067@trnddc03>中,

Bill Cunningham< no **** @ nspam.comwrote:
qI.4067@trnddc03>,
Bill Cunningham <no****@nspam.comwrote:

我的编译器在第13行和第13行给出了语法错误不要不明白。这是代码。
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);}
>#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);}



你错过了}。你有一个开放的{来自main()行,

你有一个开放的{来自主要内部的int块行。


除非你正在使用gcc或具有类似扩展名的其他编译器,

不允许定义嵌套函数,因此无法使用int chunk(){inside
main的定义。


你必须使用C90编译器,否则你将无法使用隐式int返回结果为你的
main()的定义,

然而你不会在main主体内返回任何值。

-

这是一个Usenet签名块。在我的帖子之一回复

时请不要引用它。
http://en.wikipedia.org/wiki/Signature_block



You缺少一个}。你有一个开放的{来自main()行,

你有一个开放的{来自主要内部的int块行。


除非你正在使用gcc或具有类似扩展名的其他编译器,

不允许定义嵌套函数,因此无法使用int chunk(){inside
main的定义。


你必须使用C90编译器,否则你将无法使用隐式int返回结果为你的
main()的定义,

然而你不会在main的主体内返回任何值。
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.



哦,我现在看到了。我想我想做的是在

a标题中声明函数,就像main()之上的那样,然后在它自己的c文件中定义并运行

gcc -c在它上面制作一个目标文件。我有gcc-3.4.6。那么

sizeofs会起作用吗?我在我的机器上使用int因为size_t和int

都是32位。我的机器上有16位短片,而couse的焦点是8位/ b $ b位。我只是想在我的机器上使用它,否则我会使用

size_t bs和size_t nb。但是这里 -


fwrite(n2,bs,sizeof(nb),fp); / *我需要sizeof for fwrite吗?和fread一样的
问题。 * /


Bill

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


这篇关于块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆