发现错误...... [英] Spot the error...

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

问题描述

一位同事正在阅读一些C文章,并被问到以下代码中是否有任何错误

。我们都没有发现任何

问题,我已经用最严格的

设置用VC8和GCC编译了它并没有任何注意事项。


以下是代码:


#include< stdio.h>


void usage(char * ptCommand);


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

if(argc< 2)

用法(argv [0]);


返回0;

}


无效用法(char * ptCommand){< br $>
char usageInfo [1023];


_snprintf(usageInfo,1023," Usage:%s \ n",ptCommand);
< br $> b $ b printf(usageInfo);

}


谢谢。

A colleague is reading through some C articles and was asked if there
are any errors in the following code. Neither of us can spot any
issues, I have compiled it with VC8 and GCC at their strictest
settings and got nothing of note.

Here is the code:

#include <stdio.h>

void usage(char *ptCommand);

int main(int argc, char * argv[]) {
if (argc < 2)
usage(argv[0]);

return 0;
}

void usage(char *ptCommand) {
char usageInfo[1023];

_snprintf(usageInfo, 1023, "Usage: %s \n", ptCommand);

printf(usageInfo);
}

Thank you.

推荐答案

NwsGrp1写道:
NwsGrp1 wrote:

一位同事正在阅读一些C文章并被问到是否有

是以下代码中的任何错误。我们都没有发现任何

问题,我已经用最严格的

设置用VC8和GCC编译了它并没有任何注意事项。


以下是代码:


#include< stdio.h>


void usage(char * ptCommand);


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

if(argc< 2)

用法(argv [0]);


返回0;

}


无效用法(char * ptCommand){< br $>
char usageInfo [1023];


_snprintf(usageInfo,1023," Usage:%s \ n",ptCommand);
A colleague is reading through some C articles and was asked if there
are any errors in the following code. Neither of us can spot any
issues, I have compiled it with VC8 and GCC at their strictest
settings and got nothing of note.

Here is the code:

#include <stdio.h>

void usage(char *ptCommand);

int main(int argc, char * argv[]) {
if (argc < 2)
usage(argv[0]);

return 0;
}

void usage(char *ptCommand) {
char usageInfo[1023];

_snprintf(usageInfo, 1023, "Usage: %s \n", ptCommand);



标准C中没有名为_snprintf的函数。


-

Ian Collins。

There isn''t a function called _snprintf in standard C.

--
Ian Collins.


NwsGrp1写于20/03/2007 11:44:
NwsGrp1 wrote on 20/03/2007 11:44:

一位同事正在阅读一些C文章和被问到以下代码中是否有任何错误

。我们都没有发现任何

问题,我已经用最严格的

设置用VC8和GCC编译了它并没有任何注意事项。


以下是代码:


#include< stdio.h>


void usage(char * ptCommand);


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

if(argc< 2)

用法(argv [0]);


返回0;

}


无效用法(char * ptCommand){< br $>
char usageInfo [1023];


_snprintf(usageInfo,1023," Usage:%s \ n",ptCommand);
< br $> b $ b printf(usageInfo);

}


谢谢。
A colleague is reading through some C articles and was asked if there
are any errors in the following code. Neither of us can spot any
issues, I have compiled it with VC8 and GCC at their strictest
settings and got nothing of note.

Here is the code:

#include <stdio.h>

void usage(char *ptCommand);

int main(int argc, char * argv[]) {
if (argc < 2)
usage(argv[0]);

return 0;
}

void usage(char *ptCommand) {
char usageInfo[1023];

_snprintf(usageInfo, 1023, "Usage: %s \n", ptCommand);

printf(usageInfo);
}

Thank you.



使用

printf("%s",usageInfo)

,以防ptCommand包含格式说明符。


Bavo

Use
printf("%s", usageInfo)
in case ptCommand contains format specifiers.

Bavo


NwsGrp1< nw ***** @ googlemail.comwrote:
NwsGrp1 <nw*****@googlemail.comwrote:

_snprintf(usageInfo,1023, "用途: %s \ n",ptCommand);
_snprintf(usageInfo, 1023, "Usage: %s \n", ptCommand);



(我没有_snprintf(),但确实有snprintf()。我说...... 4个人

是即将打电话给你。:)


至于错误,请查看:我将可执行文件命名为foo%s。而且当我跑的时候,
崩溃了。为什么?


-Beej

(I don''t have _snprintf(), but do have snprintf(). I say... 4 people
are about to call you on this one. :)

As for "errors", check this out: I named the executable "foo%s" and it
crashed when I ran it. Why?

-Beej


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

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