一道笔试题:linux下找bug
对linux不熟悉55555~~~,在windows下正确的,哪位大大能跳出来说一下,感激不尽
#include <stdio.h>
char *reverse(char* str)
{
int len=0, i=0;
char *pstr=str, *ptemp,*pd;
while(*++pstr)
len++;
pstr--;
//ptemp=(char*)malloc(len+1);
ptemp=(char*)malloc(len+1);
pd=ptemp;
while(len--){
*ptemp=*pstr;
ptemp++;
pstr--;
i++;
}
*ptemp=*pstr;
ptemp++;
*ptemp='\0';
return pd;
}
int main()
{
char string[13]= "hello world!";
char *pstr=string;
printf("%s", pstr);
printf("%s", reverse(pstr));
return 0;
}
while(*++pstr)
len++;
printf("%d\n", len); // 加上这个看看
这样算出来的len是11,结果ptemp只给分配了12个字节,应该需要13个字节才够用。
while(*++pstr)
len++;
len++; // 给len再加1,看看linux下结果对不对
pstr--;
恩,有道理~~windows里居然会碰巧正确
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
#include <fcnt1.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int fd_open,fd_open_create,fd_create;
if((fd_open=o ......
请问下载Linux下怎么安装cuda visual profiler啊?
另外,我只下载到1.0版本的profiler,没找到2.2版本的(我用的cuda是2.2版本的),不知道去哪儿下载?
多谢!
我知道了,其实在安装cuda的时候就已经装了 ......
在linux下,怎样编译OCI的程序?它的gcc指令是什么?我从网上找的都不能用!还有,我在linux用C与oracle连接,我都需要安装oralce的哪些软件?只需要oralce的客户端,与OCI的库么?别的还需要么?
请高手指教!
......
RT,在线等,,现在在买一个VPS 提供Arch2009.02 CentOs 5.2/5.3 Debian5.0(lenny) Fedora10(Cambridge) Fedora11(Leonidas) Gentoo 2008.0 Ubuntu 8.04.2 LTS(hardy) Ubuntu 8.10 (intrepid) ......