当前位置:首页
开发技术指南» 文章正文
    引言:

 ·调用 createcompatibledc 出错    »显示摘要«
    摘要: 一个视图类: view.h class { cbitmap m_bkmap; //用于绘制兼容位图 ...... } view.cpp onerasebkgnd(cdc *pdc) { //由于我需要一个复杂背景,我想在只在刷新背景的时候去画,而不放在 ondraw()中浪费时间; drawbk(); //函数内将复杂背景绘制于 m_bkmap; } ondraw(cdc *pdc) { ......
 ·struts群:7297119 up有分    »显示摘要«
    摘要: 欢迎加入这个struts群。 ......


紧:谭浩强的C程序设计中的一个例子,运行不了,不明白,请指教,关于字符串指针的。

我在VC6和DEVC++中运行都不行,错误出现在for(;*from!=\0;from++,to++)  
  void   copy_string(char   *from,   char   *to)  
  {  
            for(;*from!=\0;from++,to++)  
                  *to   =   *from;  
   
            *to=\0;        
         
            printf("to=%s\n",to);  
  }  
   
  int   main(int   argc,   char*   argv[])  
  {  
          char   *a   ="I   am   a   teacher.";  
    char   *b   ="you   are   a   student.";  
          printf("before   copy:\n");  
          printf("a=%s\nb=%s\n\n",a,b);  
          copy_string(a,b);  
    return   0;  
  }  
   
  为什么阿

NO.1   作者: corrupt

你该成++from   和++to     看看  
  我在网把,没编译器,我不知道

NO.2   作者: junguo

是书上源码吗?如果是的话,也太不负责任了,char   *a,char   *b指向了静态存储区的代码,是不可以改变的!代码是错的!

NO.3   作者: Darkay_Lee

int   main(int   argc,   char*   argv[])  
  {  
          char   *a   ="I   am   a   teacher.";  
          char   b[1024]   =   {0};  
          printf("a=%s\nb=%s\n\n",a,b);  
          copy_string(a,b);  
          return   0;  
  }

NO.4   作者: v41dugu

而且你的copy函数也写错了   最后输出的指针to的位置也没对嘛    
  #include   <iostream.h>  
  #include   <string.h>  
  void   copy_string(char   *from,   char   *to)  
  {  
          char   *before=to;    
  for(;*from!=\0;from++,to++)  
                  *to   =   *from;  
   
            *to=\0;        
         
            cout<<"to="<<before<<endl;  
  }  
   
  int   main()  
  {  
          char   *a   ="I   am   a   teacher.";  
  char   *b   =new   char   [strlen("you   are   a   student.")];  
  strcpy(b,"you   are   a   student.");  
          cout<<"before   copy:\n";  
          cout<<"a="<<a<<"b="<<b<<endl;  
          copy_string(a,b);  
    return   0;  
  }  
 

NO.5   作者: asphp

char   *a   ="I   am   a   teacher.";  
    char   *b   ="you   are   a   student.";  
  垃圾,这里指的是常量区域,不可改变的,但Linux下是可以改变的

NO.6   作者: adam1314

在C++中char   *a   ="I   am   a   teacher.";  
  与const   char   *a="I   am   a   teacher.";  
  是等价的,不能改变你把char   *b   ="you   are   a   student.";改成char   *b   =NULL;  
  b=malloc(strlen(a));就可以了

NO.7   作者: xiayh1002

strlen(a)<strlen(b)  
  应该给a重新分配足够大小的内存


 ·imagebutton点击时取所在行的id    »显示摘要«
    摘要: 各位高手,我在datagrid中的一列插入了imagebutton,在点击imagebutton触发相关事件时,我想得到这一行是datagrid中的第几行,请问怎么得到?先谢谢了 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE