JonsenElizee

Software Developing Blog

"An idea is fragile . It can be killed by a scornful smile or a yawn .It can be mound down by irony and scared to death by a cold look."
"Most cultures throughout human history have not liked creative individuals .They ignore them or kill them.It is a very efficient way of stopping creativity."

------Advertising boss Charles Browe and Howard Gardner ,professor at Harvard

   :: 首页 :: 新随笔 ::  ::  :: 管理 ::
1 int string2long(char* str, long* rtv)
2 {
3     for(int i = strlen(str), j = *rtv = 0*str >= '0' && *str <= '9'; i--, str++){
4         *rtv += (long)((*str - '0')*(pow(10, i-1)));
5     }
6     return *str == '\0' ? 1 : 0;
7 }
Please pay attention to j = *rtv = 0;
if there is no "j = ", *rtv will be redefined as int *rtv after ", " and address of rtv will be 0xcccccc.
So, inorder to set value of rtv in if sentence, just use a non-usage variable j.

to invoke the function in this way:

long rtv;
if(string2long("321", &rtv)) printf("rtv = %ld\n", rtv);
else puts("failure");


posted on 2010-10-20 14:29 JonsenElizee 阅读(301) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


By JonsenElizee