LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 826|回复: 1

新学 C++ 问个问题

[复制链接]
发表于 2006-4-30 12:23:32 | 显示全部楼层 |阅读模式
以下程序 在Windows2k3下写的 内容就是想在屏幕顶部中央 显示copyright的内容
编译通过 但是 运行时
出现
1.exe -Application Error

The instruction at "0x77bd6f33" referenced memory at "0x00000020". The memory could not be "read".



/*-------------------------程序-------------------------------*/
#include <iostream.h>
#include <string.h>
#define line_max 80
char *copyright;
char *return_copyright(char *copyright)
{
    int i;
    int line_start2char_start;
    char *tmp;
    line_start2char_start=line_max-strlen(copyright)/2;
    for(i=1;i<=line_start2char_start;i++)
    {
        strcat(tmp,(char *)32);
    }
    strcat(copyright,tmp);
    return tmp;
}
int main()
{
    copyright="Sim Studio";
    cout<<return_copyright(copyright)<<endl;
}

好心人帮我看看 错在什么地方~  谢谢啦~~
发表于 2006-4-30 13:12:31 | 显示全部楼层
tmp指针赋值吗?

http://www.cplusplus.com/ref/ 的例子:
  1. char *  strcat ( char * dest, const char * src );
  2. Append string.
  3.   Appends src string to dest string. The terminating null character in dest is overwritten by the first
  4. character of src. The resulting string includes a null-character at end.
  5. Parameters.
  6. dest
  7.     Pointer to a null-terminated string with [b]enough space allocated to contain both src and dest.[/b]
  8. src
  9.     Null-terminated string to append.
  10. Return Value.
  11.   dest is returned.
  12. Portability.
  13.   Defined in ANSI-C.
  14. Example.
  15. /* strcat example */
  16. #include <stdio.h>
  17. #include <string.h>
  18. int main ()
  19. {
  20.   char str[80];
  21.   strcpy (str,"strings  ");
  22.   strcat (str,"have been ");
  23.   strcat (str,"concatenated.");
  24.   puts (str);
  25.   return 0;
  26. }
  27. Output:
  28. strings have been concatenated.
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表