由买买提看人间百态

topics

全部话题 - 话题: char
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
l***a
发帖数: 5114
1
我是来推荐书滴。。。。。
Flowers for Algernon,(作者Daniel Keyes,在去年去世了。) 可能是我去年看过
的,最让我感动的小说了。虽然结局没有任何悬念,书的最后两页,我还是淌着眼泪分
了很多次才看完的。。。然后,我默默坐在黑暗里candy rush了很久很久~~~~依然是很
难从伤感脱逃出来。。。
Flowers for Algernon (FA) 原本只是短篇,59年发表以后就拿了Hugo奖,66年改成
长篇以后又一次得了 Nebula Award for Best Novel。。。介两个奖算是科幻界的金球
和奥斯卡了吧。。。这部小说对心理的刻画细致入微,对人性的描写更是精准犀利。排
除科幻的元素,这也绝对是那得一见的能够“涤荡心灵”的好文。
故事本身并不很复杂:智力有缺陷的charly(IQ=69)是一家面包店的杂工。在一次实
验性的手术以后,他如愿以偿地慢慢聪明起来。不仅如此,在他的智力在术后继续攀升
,最后达到“旷世奇才”的水平。可惜,手术带来的智力大爆发只是暂时的。巅峰过后
注定是不可抵挡的溃退。在慢慢重新变回智障以后,charly又回到面包店,... 阅读全帖
p**o
发帖数: 3409
2
手写了一些C扩展,有些返回多重指针的函数不知道怎么用SWIG来包来供Python调用……
比如下面这个strsplit()函数,返回的是char**,怎么改才能让Python收到一个list (
of strings)?
http://www.swig.org/tutorial.html
我只是照tutorial简单地把函数声明抄进.i文件,Python中调用时返回的是

#include
#include
#include
/* Split an input string 'instr', using a set of given delimiters, to an
array of strings of at most 'maxparts' parts. */
char **strsplit (const char *instr, const char *delimiters, size_t maxparts)
{
char *... 阅读全帖
f*******n
发帖数: 12623
3
一个const是关于pointer指向的那些char。另一个是关于pointer变量本身。
const char *
char const *
这两个是一样的。就是说pointer本身可以变,但是不能通过pointer来改指向的char。
char * const
这是说pointer本身不能变,但是可以通过pointer来改指向的char。
const char * const
char const * const
这两个是一样的。就是说pointer本身不能变,也不能通过pointer来改指向的char。
e******o
发帖数: 757
4
来自主题: Programming版 - 问一个 char * 和 char [] 的问题
刚刚写了一个小code
char *a = "abc";
char b[] = "abc";
reverse(a, a+3);
reverse(b, b+3);
第一个reverse报错了,第二个没有,是不是char *a ="abc" 得到的是pointer to
constant, 而char b[] = "abc" 得到的是一个regular 的pointer?
如果是的话,能不能这样解释,char *a="abc" 是不是先生成一个临时的const char *
temp = "abc", 然后a == temp. 而 char b[] = "abc" 是建立一个名字为 b 的array.
G*******n
发帖数: 2041
5
【 以下文字转载自 JobHunting 讨论区 】
发信人: GreenBean (I am THE Greenbean), 信区: JobHunting
标 题: char *p = "string literal"; 和 char a[] = "string liter
发信站: BBS 未名空间站 (Tue Aug 12 01:56:44 2008)
char *f(void)
{
char a[] = "string literal";
return a;
}
//bad: returning address of local variable or temporary
char *f(void)
{
char *p = "string literal";
return p;
}//Is this good?
这里这个p怎么理解,不也是local的吗?据说是static的所以没问题?可是没定义是static
的啊?
B*******g
发帖数: 1593
6
来自主题: Programming版 - 问个char * 的问题
char test[] = "AB";
char * a = "AB";
char * b = test;
这里面literal string (a) 和 char array (b)使用起来有没有区别?
我知道a[0] = a[1];会产生run time error, b[0]=b[1];却可以
莫非a[0]返回的是char const & 而b[0]是 char &?如果你不知道 a,b如何赋值的话有
没有办法
知道他们是literal string还是char array?
B*******g
发帖数: 1593
7
来自主题: Programming版 - 问个char * 的问题
但test我看定义也知道是char array
char test[] = "AB";
char * a = "AB";
char * b = test;
typeid() a 或b 都是 char *
问题是
b[0]=b[1]; 运行通过但是
a[0]=a[1]; 就报exception .........Access violation writing location
0x009d7854
我猜原因是a[] 返回的是 char const &..而b[]返回的是 char &;或者是别的原因?
d****n
发帖数: 1637
8
来自主题: Programming版 - char s[]和char *ps的不同
char *p="abc"; 在代码段,immutable.
any write operation will cause segfault.
char a[]="abc"; stack, read/write okay
#include
#include
int main(){
char *p="abc";
printf("%p\n",p );
*(p+1)='w'; //segfault
free(p); //segfault or
glibc fault
p =(char *) malloc (sizeof(char)*4) ; //okay, but previous "abc" lost
printf("%p\n",p );

char a[]="def";
printf("%p\t%s\n",a,a); ... 阅读全帖
v****s
发帖数: 1112
9
来自主题: Programming版 - 怎么得到char *分配空间的大小?
const int MAX = 500;
char *src = (char*)malloc(MAX*sizeof(char));
for( int i = 0; i printf("%d\n",sizeof(src));
结果是4,而不是500,而用 char src[MAX] 就可以得到这个正确的sizeof(src)。
char *src 和 char src[] 都是分配在heap上面的么? sizeof()函数具体是怎么实现
的?
谢谢!!
s****n
发帖数: 700
10
来自主题: Programming版 - C++: use char * in Map
I get some problem here.
char a[40];
char b[40];
sprintf(a, "%s", "x1");
sprintf(b, "%s", "x2");

struct cmp_str
{
bool operator()(char const *a, char const *b)
{
return strcmp(a,b) < 0;
}
};

typedef std::map MAPIDS;
MAPIDS m_mapIds;
std::pair< MAPIDS::iterator, bool > _pr_id = m_mapIds.insert( MAPIDS::value_
type(a , b ));
printf("%s %s\n", _pr_id.first, _pr_id.second // look likes I can't
retrieve a and b using the pair... 阅读全帖
s***e
发帖数: 122
11
我觉得区别可能不是在这里,我刚才测试了一下,以下程序编译是可以的,虽然g++给
出了从string constant to char * 的警告,但是这还是说明char * s[]是可以作为变
量的。呵呵,希望大家不要觉得我唧唧歪歪。
int main(int argc, char* argv[]) {
char * s[] = {"a", "b"};
return 0;
}
s****n
发帖数: 1237
12
来自主题: Programming版 - 请教char *和char []的判断
在练习一道面试题
Implement an algorithm int removeDuplicate(char[] s)
For instance change ”abbcccdda” to “abcda” and return 4(the number of
characters deleted).
我自己写了一个
int removeDuplicateString(char str[]){
int count = 0;
int pos = 0;
char *c = str;
while(*c){
if(*c == *(c+1)){ count+=1;}
else{str[pos]=*c; pos++;}
c++;
}
str[pos]='\0';
return count;
}
但是调用的时候
char string[] = "ccc"; int n =
X****r
发帖数: 3557
13
来自主题: Programming版 - 请教char *和char []的判断
你这个程序还有一些可改进的地方:
1)count是不需要的,最后两个指针的差就是要返回的结果。
2)对于函数参数来说,char str[]和char *差别不大,
你这种情况用后者更方便,可以不用pos。
int removeDuplicateString(char* str){
char *c;
for(c = str; *c; c++)
if(*c != *(c+1)) *str++=*c;
*str = '\0';
return c - str;
}
就我个人而言会把*(c+1)写成c[1],不过这个就见仁见智了。
f*******n
发帖数: 12623
14
来自主题: JobHunting版 - 如何判断char的赋值有没有溢出
"unsigned char" can hold 0 - 255
"signed char" can hold -128 to 127
"char" can be either signed or unsigned char, depending on the
implementation
I**********s
发帖数: 441
15
local = (char *(*)()) inc_1;
char *(*)() is the pointer to a function.
This function takes no argument and return type is char *.
So the above statement casts inc_1 to the type of char *(*)()
and assign it to function pointer local.
"C traps and pitfalls" has an example like this:
(* (void (*) ()) 0)();
What this does is to cast address 0 as a function pointer void (*) (),
which is a function takes no argument and return type is void.
It then dereference this pointer and execute it.
This is used
g*********s
发帖数: 1782
16
来自主题: Programming版 - free(char *)的问题 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: JobHunting
标 题: free(char *)的问题
发信站: BBS 未名空间站 (Mon Dec 10 13:10:23 2007)
下面的代码有没有内存泄漏?如果希望提前释放掉str[3,4,5]的空间如何操作?
char *str=(char *) malloc(sizeof(char)*(strlen("hello")+1));
strcp(str, "hello");
str[2]=0;
printf("%s\n",str);
free(str);
r*****e
发帖数: 792
17
从键盘输入一串字符串,长度不定,所以用char[max]不够好,
在不用string类型的情况下怎么将这个字符串存在char/char*
类的变量中呢?在下面code的基础上如何修改最好?
多谢!
char buffer[max];
cin.getline(buffer, 100);
m*******o
发帖数: 264
18
来自主题: Programming版 - 问个char*的问题
#include
using namespace std;
char* f(int i);
void main()
{
cout << f(1) << endl;
}
char* f(int i) {
char buffer[20];
strcpy(buffer, "test");
return buffer;
}
函数f到底返回的是什么,应该是个指向char类型的指针吧。
但为什么cout << f(1); 输出的是整个array: test?
还有return buffer; 返回的是buffer[20]的初始地址吧?
返回指针的函数的返回值必须是个地址吗?
r*******y
发帖数: 1081
19
来自主题: Programming版 - const char *p, is it ok to change p[1] ?
for example
char a[] = "hello";
const char * p = a;
p[1] = '3'; //is this ok?
I know it is not ok for this: *p = '3'
since p point to a const char.
But it is not saying p+1 is pointing to a const char.
so p[1] ='3' would have been ok.
But I find that it is not ok to do this: p[1] = '3' after I compile it
Any comments? seems a stupid question. thanks
r*e
发帖数: 112
20
I am try to use one function.
int execvp (const char *file, char *const arv[]);
but , I am confused by 'const char *' and 'char *const'
what is the differnce between them?
Tx!
l**********r
发帖数: 4612
21
【 以下文字转载自 Programming 讨论区 】
发信人: linuxbeginer (linux), 信区: Programming
标 题: Char x[] = "abc"; 是在heap还是stack上?
发信站: BBS 未名空间站 (Mon Oct 19 17:15:12 2009, 美东)
Char x[] = "abc";
我认为内存allocated 在heap上。对么?
suppose char x[] is defined at global scope.
b*******y
发帖数: 239
22
来自主题: JobHunting版 - 请教operator const char*() 的问题
原题也是在这个版上有人发的C++的其中一题,已copy下来:
class Person{
public:
Person(const char* szName);
const char* GetName() const;
/*put a function here*/
private:
char *m_szName;
};
int main()
{
Person person("John");
std::cout << Person;
return 0;
}
Referring to the sample code above, which one of the following member
functions do you add at the comment to support std::cout << person
statement?
A. std::string operator() { return GetName(); }
B. std::string ToString() { retur
h*****f
发帖数: 248
23
来自主题: JobHunting版 - 如何判断char的赋值有没有溢出
Hmm...a char can hold 0x0-0xFF. 128=0x80...so no overflow..
I guess the question is to detect whether the input occupies more than 1
byte?
You probably could *if* it were foo(char*) or foo(char&).
k***x
发帖数: 6799
24
来自主题: JobHunting版 - void * 和 char * 有区别吗?
In C++, there are three distinct character types:
char
signed char
unsigned char
l***y
发帖数: 37
25
来自主题: JobHunting版 - question about char pointer
大牛请问
why can't print out c 在内存中的地址
---------------------------------
char c='3';
char *cptr=&c;
char **cptrptr=&cptr;
cout <<"Address of Var i=" <
B*****g
发帖数: 34098
26
what will be to_char(char/varchar2) return? char or varchar2?
http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/functions133a.htm#1003495
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions179.htm#i1006717
http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_functions_2113.htm
9i return database character set. what is database character set.?
10g return VARCHAR2.
11g return text? what is test, is it just char?
SELECT *
FROM tab1
WHERE col1 = 'abc'
'a
B*****g
发帖数: 34098
27
如果没有人用char做column就没问题。
咱们哪儿bt很多,非要用char。
结果就是
Tab1(ID number, char_col char(10))
record(1, 'abc ')
select count(1)
from tab1
where id = 1
and char_col = 'abc '
return 1
用to_char也解决不了。
O*******d
发帖数: 20343
28
来自主题: Programming版 - char[] 和 char*有什么区别?
你可以用sizeof看看char[8]和char*的大小.
h**o
发帖数: 548
29
char t1;
char t2;
t1 = ‘b’;
t2 = ntohl(t1);
printf(“t1 = %x, t2 = %x”, t1, t2);
结果 t2 != t1.
照理说 char = one byte, 那么用ntohl 或htonl 应该没 影响啊。
请指正。
s***e
发帖数: 122
30
那我想我们可以把区别解释为pt1是一个指向char *的指针,而pt2是一个char *的数组
。问题就变成了指针和数组的区别了。
k**f
发帖数: 372
31
allocate memory enough to hold 12 pointers to char, and cast the pointer the
the head of the allocated memory to a char** before assigning it to
variable 'a'.
s*****n
发帖数: 3
32
来自主题: Programming版 - how can I convert CString to char*?
我刚开始自学.我是这么写的:
char *tt =(char *)(LPCTSTR)mycstring;
AfxMessageBox((LPCTSTR)tt);
这么看输出是正确的,但是我想用tt[0]..tt[i]..去得到一个个字符,
却发现只有tt[0]是正确的,后面的都是空的(至少打印不出来)
我应该怎么把CString转化为char*呢? 非常感谢!
X****r
发帖数: 3557
33
来自主题: Programming版 - A question about cost char*
字符串常量类型为char*而不是const char*是C语言的历史遗留问题。
你自己程序里把字符串常量类型当const char*看待就好了。
U********d
发帖数: 577
34
来自主题: Programming版 - 问个char * 的问题
这个和编译有关,几乎所有的编译器都会将[]=""内容放在设定为rw的栈上,而把char
*x="xx"中的xx放在静态数据区而设定为r。
这样就可以解释你的问题了,对于char test[] = "AB";执行的时候确实在栈上面分配
了3个字节的内存,这部分地址是可读写的,而且在test的生命周期内这部分内容你可
以随意读写。但是对于char * a = "AB";这里的AB不是放在栈上,而是放在全局数据段
,这里的a在32位操作系统下只是一个4字节的指针,指向这个只具有r属性的全局数据。
C在编译的时候并不检查读写权限或者越界之类的事情,所以编译没有问题。但是在运
行的时候,a[0] = a[1];对一个r属性全局数据段的数据进行写操作,所以会挂掉。b=
test后b[x]=x的操作是对栈上rw的数据操作,所以没有问题。
t****t
发帖数: 6806
35
来自主题: Programming版 - 请教char *和char []的判断
上个月刚有人问过. 答案是在函数内不可能判断; 把字符串常量给一个const char*就
不会出现这样的问题了, 因为用const char*不能调用你写的这个函数.
s****n
发帖数: 700
36
来自主题: Programming版 - help about convert a char array in c
char text[64] = "SPY 121231C00095000";
Symbol - 6 bytes
Year - 2 bytes
Month - 2 bytes
Day - 2 bytes
Call/Put Indicator - 1 byte
Strike Dollar - 5 bytes
Strike Decimal - 3 bytes
I want to convert it to the format like "SPY,C,121231,95.0"
The only way I know is to loop the array and set some if statement to get
rid of empty char for Symbol, and get rid of 0 char for strike.
Is there any more efficient way to handle the case. Thank you very much.
X****r
发帖数: 3557
37
来自主题: Programming版 - const char *p, is it ok to change p[1] ?
type of p is const char *, so type of p+1 is also const char *,
thus type of p[1], which is *(p+1), is const char, and you can't
assign to it.
y**b
发帖数: 10166
38
来自主题: Programming版 - char s[]和char *ps的不同
void func() {
char s[]="abc"; // 在stack上分配空间存储"abc",sizeof(s)等于4
int i[]={1,2,3}; //同上, sizeof(i)等于12
char *ps="def"; // 在常量区存储"def",sizeof(ps)==8
int *pi=new int[3]; // 在heap分配空间存储,sizeof(pi)==8
delete [] pi;
}
以上对否?
这个常量存储区同初始化数据段/非初始化数据段是什么关系?
看网上有人把c/c++内存布局描述如下:
1、栈区(stack)
2、堆区(heap)
3、全局区(静态区):初始化数据段/非初始化数据段
4、文字常量区
5、程序代码区
z****e
发帖数: 2024
39
来自主题: Programming版 - char s[]和char *ps的不同
char s[] is a constant pointer which can not be changed.
char *ps is a regular pointer.
s********k
发帖数: 6180
40
来自主题: Programming版 - char s[]和char *ps的不同
char *ps is the constant pointer. if you assign
char *ps = "def" later, there will be linker error for segmentation fault.
t****t
发帖数: 6806
41
in c++03 only accept const char* as filename, so it's normal peopl
e use const char*. if you use string, you will have to write
file.open(fname.c_str());
which is kind of ugly. c++11 fixed this problem, so you can use string now.
S*A
发帖数: 7142
42
来自主题: Programming版 - 求教char**&与char*的不同
reference type 是 C++ 里的吧,C 没有 reference type。
& 在 C 里面只能在 expression 里面用。
char **& 不是一个valid C type。
char * 是一个 C type。
w*******y
发帖数: 60932
43
Char-Broil Quantum Infrared Urban Gas Grill - $202.49 with Free Shipping!!!
Lowest Price ever on a very good INFRARED GRILL!!!
Link:
http://www.amazon.com/Char-Broil-Quantum-Infrared-Folding-Shelv
Price Comparison: Link:
http://www.google.com/products/catalog?q=Char-Broil Quantum Infrared Urban Gas Grill&hl=en&prmd=imvns&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1366&bih=653&um=1&ie=UTF-8&tbm=shop&cid=16239845960571288462&sa=X&ei=AKEhT57XBKXXiALd6_HmBw&ved=0CGoQgggwAA
l**********r
发帖数: 4612
44
If it's
char * x = "abc";
then you are right. But for
char x[] = "abc";
I think you are wrong.
Anybody can confirm with that?
y*****a
发帖数: 171
45
how could it be in the heap, you never call alloc for this, do you. it is
done by the compiler. you got it clear?
l.c
char *x1="abc1";
char x2[]="abc2";
gcc -s -c l.c
cat l.s
.file "l.c"
.globl x1
.section .rodata
.LC0:
.string "abc1"
.data
.align 4
.type x1, @object
.size x1, 4
x1:
.long .LC0
.globl x2
.type x2, @object
.size x2, 5
x2:
.string "abc2"
.ident "GCC: (GNU) 4.1.2 2008
f****4
发帖数: 1359
46
来自主题: JobHunting版 - 请教operator const char*() 的问题
conversion Operator :)
// code explains itself
class Test{
public:
operator const char*(){cout<<"Test"< };
void f(const char*)
{
cout<<"f()"< }
int main(){
Test t;
f(t);
return 0;
}
c**y
发帖数: 172
47
函数声明如下
void function1(const char *a) {
...
...
return;
}
如何能在函数function1中访问a呢?我只想到用strcpy的方法把a复制到另外一个char
array中。有没有什么办法直接访问a,而不使用额外的内存?
g***s
发帖数: 3811
48
题目都说了是char[]. 结果你改成int[]. 按你的理解,还要先把char[]里面多位合并
成一位来做?你要这么专我也没啥好说的了。

10001
d**********x
发帖数: 4083
49
来自主题: JobHunting版 - new char[i](); 跟 new char[i];有区别么
char的默认"构造"将使其初始化为0
j*****y
发帖数: 1071
50
来自主题: JobHunting版 - void * 和 char * 有区别吗?
signed char 和 unsigned char 是不是就是和 一个 byte的integer的感觉一样阿 ?
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)