将char设置为空 [英] set char to empty
问题描述
如何将char []设置为空?
让我说,我有,
char test [20];
我可以这样做:
* test = NULL;
谢谢。
Magix写道:
如何将char []设置为空?
我要说,
char test [20];
char test [20] ="" ;;
如果你想将它初始化为一个空字符串。
我可以这样做:
* test = NULL;
* test(或test [0])是一个字符。
NULL是一个指针。
你不能将指针值赋给字符。
* test = 0;
test [0] = 0;
或任何几个同义语句都可以。
On Mon,2 2004年8月12:50:39 + 0800,Magix <毫安*** @ asia.com>写道:
如何将char []设置为空?
让我说我有,
char test [20];
您无法将数组设置为空。 test是一个20 char的数组。这20个中每个
都有一个值(即使你不知道它的价值是多少)。
你可以将数组设置为空(strlen = 0)字符串设置
test [0]到''\0''。有几种方法可以做到这一点:
作为定义的一部分
char test [20] ="" ;;
char test [20] = {''\ 0''};
通过作业
test [0] =''\ 0'';
通过函数
strcpy(test,"");
memset(test,' '\''',sizeof test);
我可以这样做:
* test = NULL;
不能。您不能在赋值运算符的左侧放置一个数组。
<<删除电子邮件的del>>
Magix在02/08/04写道:
如何将char []设置为空?
让我说,我有,
char测试[20];
我可以这样做:
* test = NULL;
你从哪里得到的? Certainely不是来自一本好的C书。 ''测试''是一个数组,它是一个常量指针。它不能被修改。
空是什么意思?对象始终具有值。它永远不会是b $ b''空''。
也就是说,一个特殊的值可能会有空的语义。这是一个约定的问题。如果你在谈论一个字符串,那就是'b $ b'被认为是''空''或"当你在索引0处得到0时。
char test [20];
test [0] = 0;
或
* test = 0;
或
strcpy(测试,");
因为"是硬编码
char anonymous [] = {0};
-
Emmanuel >
C-FAQ: http:/ /www.eskimo.com/~scs/C-faq/faq.html
C是一个敏锐的工具
Hi,
How do I set the char [ ] to empty ?
let say I have,
char test[20];
can I do like this :
*test = NULL;
Thanks.
Magix wrote:
Hi,
How do I set the char [ ] to empty ?
let say I have,
char test[20];
char test[20] = "";
if you want to initialize it to an empty string.
can I do like this :
*test = NULL;
*test (or test[0]) is a char.
NULL is a pointer.
Thou shalt not assign pointer values to chars.
*test = 0;
test[0] = 0;
or any of several synonymous statements will do.
On Mon, 2 Aug 2004 12:50:39 +0800, "Magix" <ma***@asia.com> wrote:
Hi,
How do I set the char [ ] to empty ?
let say I have,
char test[20];
You cannot set an array to empty. test is an array of 20 char. Each
of those 20 has a value (even if you don''t know what the value is).
You can set the array to an empty (strlen = 0) string by setting
test[0] to ''\0''. There are several ways to do this:
As part of the definition
char test[20] = "";
char test[20] = {''\0''};
Via an assignment
test[0] = ''\0'';
Via a function
strcpy(test,"");
memset(test,''\0'',sizeof test);
can I do like this :
*test = NULL;
No. You cannot place an array on the left of the assignment operator.
<<Remove the del for email>>
Magix wrote on 02/08/04 :
How do I set the char [ ] to empty ?
let say I have,
char test[20];
can I do like this :
*test = NULL;
Where did you get that? Certainely not from a good C-book. ''test'' being
an array, it''s a constant pointer. It can''t be modified.
What do you mean by ''empty''? An object has always a value. It is never
''empty''.
That said, a peculiar value could have the semantics of ''empty''. Its a
matter of convention. If you are talking about a string, it''s
considered ''empty'' or "" when you have a 0 at index 0.
char test[20];
test[0] = 0;
or
*test = 0;
or
strcpy (test, "");
because "" is hard coded
char anonymous[] = {0};
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
这篇关于将char设置为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!