C++博客 联系 聚合 管理  

Blog Stats

随笔档案

研发里程表

2009年8月14日 #

char str[20],*p=str;
scanf(
"%s",p[2]);

 
 

这段代码正确吗?



将错就错换一个考法吧,如何让这段代码正常运行呢?

下面列了我能想到的几个方法

1.         通过宏

#define scanf()  scanf("%s",&str[2])

 
 

2.         重载

 

namespace
{
void scanf(const char*pfmt, char &pR)
{
       
char*= &pR;
       ::scanf(
"%s",p);
}
};
 

 

3.         还是宏

 

#define char unsigned long
char str[20],*p=str;

p[
2]=(unsigned long)&p[2];
scanf(
"%s",p[2]);
 

 


  

4.         或者插入

unsigned 
long pdw[3];
 pdw[
2]=(unsigned long)&p[2];
 
#define p pdw
 


 

posted @ 2009-08-14 09:53 wangjinhu 阅读(1275) | 评论 (6)编辑 收藏

仅列出标题