对C的怀疑 [英] Doubts on C

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

问题描述

亲爱的所有


以下是我在学习C时得到的一些疑问


1. C中是否有任何方法我们可以在一个单元中处理整个字符串



2.是否有任何方法可以使命令行参数

可用于其他函数没有将它们作为参数传递给

函数。

3.是否为calloc和malloc分配内存的限制,

I假设我可以将整个记忆分配到一个

插槽中,我可以在一个插槽中分配堆的总内存。

我不确定以上。请让我。

解决方案

2005年6月13日星期一07:22:40 -0700,ranjeet.gupta写道:<亲爱的所有

以下是我在学习C时得到的一些疑问

1. C中是否有任何方法我们可以在一个单元中处理整个字符串



有各种标准库函数,如strcpy()和strlen()

它适用于整个字符串。

2.是否有任何方法可以使命令行参数可用于其他函数而不将它们作为参数传递给函数。


您可以随时将argc和argv存储在静态或全局中。 vaiables和

访问函数中的那些。通过

参数通常更好的做法。

3.他们为calloc和malloc分配内存的限制,
我想会有我可以在一个插槽中分配完整的内存
i,我可以在一个插槽中分配的堆的总内存。我不确定上述情况。请允许我。




这取决于具体实现,它有多少内存可用,b $ b可用,最大大小为它可以支持的对象等等。您可以请求的最大值是您可以传递给

函数的最大值。 malloc()接受一个size_t类型的参数,该参数应该能够在托管的

环境中获取至少32767(C90)或65535(C99)的值(

)(正常的)。这并不意味着malloc()会成功获得比这更低的价值,它可能没有足够的资源来兑现你的

请求。


劳伦斯


ra ** *********@gmail.com 写道:

1. C中是否有任何方法可以处理整个字符串
在一个单元中


你的意思是什么?

2.是否有任何方法可以使命令行参数可供其他功能使用没有将它们作为参数传递给函数。


当然,将它们复制到全局变量。


static int myargc;

static char ** myargv;


int main(int argc,char ** argv)

{

myargc = argc;

myargv = argv;

...

返回0;

}

3.是他们的限额为了为calloc和malloc分配内存,我想我可以在一个插槽中分配整个内存,我可以在一个插槽中分配堆的总内存。




什么是堆? ;-)





Lawrence Kirby写道:

2005年6月13日星期一07: 22:40 -0700,ranjeet.gupta写道:

亲爱的所有

以下是我在学习C时获得的一些疑惑
< 1.在C中是否有任何方法可以在一个单元中处理整个字符串
有各种标准库函数,如strcpy()和strlen()
它可以处理整个字符串。

2.是否存在任何方法使命令行参数可用于其他函数而不将它们作为参数传递给
函数。



您可以随时将argc和argv存储在静态或全局中。 vaiables和
访问函数的那些。通过
参数通常是更好的实践。




int fucntion(int,FILE * fp);


int main(int argc,Char * argv []){


FILE * fp = fopen(" argv [1]"," r + b") ;

函数(argc,fp);

返回0;

}


int fucntion (int pased_argc,FILE * fp){


/ *你在这里处理你的数据* /


return(/ *所需的值到被重新调整* /);

}


所以你的意思是这样的?假设我有2个参数,我将b $ b用作命令行参数,那么我可以将

相同的文件也存入另一个文件吗?我目前没有编译器来检查



如果上面有更好的解决方案,请告诉我(如果

以上是正确的),


问候

Ranjeet

3.他们对分配内存的限制对于calloc和malloc,
我想我可以在一个插槽中分配完整的内存
i,我可以在一个插槽中分配的堆的总内存。我不确定上述情况。请让我。



这取决于具体的实现,它有多少可用的内存,它可以支持的最大对象大小等等。您可以请求的最大值是您可以传递给
函数的最大值。 malloc()接受一个size_t类型的参数,该参数应该能够在托管的
环境(正常环境)中获取至少32767(C90)或65535(C99)的值。这并不意味着malloc()的成功价值低于此值,它可能没有足够的资源来履行你的
请求。

劳伦斯




Dear All

Below are the few doubts which I got while studying about C

1. Is there any method in C by which we can process the entire string
in one unit,
2. Does there exist any way to make the command line arguments
available to other functions without passing them as arguments to
the function.
3. Is their limit for alloctaing the memory for calloc and malloc,
I suppose There will be I can allocate whole the memeory in one
slot i,e total memory of the Heap I can allocate in one slot.
I am not sure about the above. Please do let me.

解决方案

On Mon, 13 Jun 2005 07:22:40 -0700, ranjeet.gupta wrote:

Dear All

Below are the few doubts which I got while studying about C

1. Is there any method in C by which we can process the entire string
in one unit,
There are various standard library functions such as strcpy() and strlen()
which work on entire strings.
2. Does there exist any way to make the command line arguments
available to other functions without passing them as arguments to
the function.
You could always store argc and argv in static or "global" vaiables and
access those from the function. It is usually better practie to pass as
arguments though.
3. Is their limit for alloctaing the memory for calloc and malloc,
I suppose There will be I can allocate whole the memeory in one slot
i,e total memory of the Heap I can allocate in one slot. I am not
sure about the above. Please do let me.



That''s up to the particular implementation, how much memory it has
available, the maximum size of object it can support and so on. The
largest value you can REQUEST is the largest value you can pass to the
function. malloc() takes an argument of type size_t which should be able
to take values up to at least 32767 (C90) or 65535 (C99) in a hosted
environment (a normal one). That doesn''t mean malloc() will succeed for
values less than that, it may not have the resources to honour your
request.

Lawrence


ra***********@gmail.com wrote:

1. Is there any method in C by which we can process the entire string
in one unit
What do you mean?
2. Does there exist any way to make the command line arguments
available to other functions without passing them as arguments to
the function.
Sure, copy them to global variables.

static int myargc;
static char **myargv;

int main(int argc, char **argv)
{
myargc = argc;
myargv = argv;
...
return 0;
}
3. Is their limit for alloctaing the memory for calloc and malloc,
I suppose There will be I can allocate whole the memeory in one
slot i,e total memory of the Heap I can allocate in one slot.



What''s a heap? ;-)




Lawrence Kirby wrote:

On Mon, 13 Jun 2005 07:22:40 -0700, ranjeet.gupta wrote:

Dear All

Below are the few doubts which I got while studying about C

1. Is there any method in C by which we can process the entire string
in one unit,
There are various standard library functions such as strcpy() and strlen()
which work on entire strings.

2. Does there exist any way to make the command line arguments
available to other functions without passing them as arguments to
the function.



You could always store argc and argv in static or "global" vaiables and
access those from the function. It is usually better practie to pass as
arguments though.



int fucntion(int, FILE *fp);

int main (int argc, Char *argv[]) {

FILE *fp = fopen("argv[1]", "r+b");
function(argc, fp);
return 0;
}

int fucntion (int pased_argc, FILE *fp) {

/* you process your data over here */

return (/* Desired value to be retunred */);
}

So you mean like this ?? suppose I have the 2 arguments which I
I am using as the comand line argument, So can I access the
same file into the other file also?. I dont have the compiler to
check at present.

And also let me know if there is better solution then above (If
above is correct),

Regards
Ranjeet

3. Is their limit for alloctaing the memory for calloc and malloc,
I suppose There will be I can allocate whole the memeory in one slot
i,e total memory of the Heap I can allocate in one slot. I am not
sure about the above. Please do let me.



That''s up to the particular implementation, how much memory it has
available, the maximum size of object it can support and so on. The
largest value you can REQUEST is the largest value you can pass to the
function. malloc() takes an argument of type size_t which should be able
to take values up to at least 32767 (C90) or 65535 (C99) in a hosted
environment (a normal one). That doesn''t mean malloc() will succeed for
values less than that, it may not have the resources to honour your
request.

Lawrence




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

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