ChinaUnix.net
相关文章推荐:

返回字符串指针赋值给字符串数组名时出错

下面这个代码里报错说“Line 16 incompatible types in assignment”,我不知为什么会出这种问题,请各位指点,谢谢! /* Two D array pointer assignment from string-returning functions*/ #include #define NAM 2 #define LEN 21 char * retinput(void); int main(void){ char names[NAM][LEN]; int i; for(i = 0; i < NAM; i++){ names = retinput(); /*报错说这里的赋值类型不...

by mcmay - C/C++ - 2008-11-11 23:40:33 阅读(5327) 回复(5)

相关讨论

main函数中要读到整个文件,调用函数: readfile(char * filename, char * file_buf); main函数中定义: char * file_content; main函数中调用: readfile(filename,file_content); file_buf在函数readfile中明明已经读出内容,为什么file_content总是空? 请指点,多谢!

by gridbird - C/C++ - 2007-12-11 21:12:28 阅读(5619) 回复(6)

[code]#include ; char * find_char(char const *source,char const *chars) { char a; int i,j; if ( (source == NULL) || (chars == NULL) ) return NULL; j=0; while (*(source+j) != '\0'){ i=0; while (*(chars+i)!='\0'){ if (*(chars+i) == *(source+j)) ret...

by ccf - C/C++ - 2005-06-14 09:45:27 阅读(1332) 回复(4)

请问在定义一个字符数组之后,如何把一个字符串付给它,而不是在定义赋值,谢谢!!!

by taichilau - C/C++ - 2006-01-13 10:35:20 阅读(1079) 回复(3)

问题, 处理特殊字符不正确,使用网上的方面也不成功, 下面是代码,但特殊字符没有显示出来,请下载附件。 [code]class string_handler { // 1: means the string is utf-8 // 0: means the string is gbk/gb2312 static $isUtf8 = 1; public function __construct(){ die("not allow to implement a new object"); } public static function strlen($str) { return self::$isUtf8 ? strlen(self::...

by guishoudaoge - PHP - 2008-03-18 09:19:19 阅读(1671) 回复(3)

下面代码: [code]#include main() { void copy_string(char *from,char *to); char *a="I am a teacher."; char *b="you are a student."; printf("string a=%s\nstring b=%s\n",a,b); printf("copy string a to string b:\n"); copy_string(a,b); printf("\nstring a=%s\nstring b=%s\n",a,b); } void copy_string(char *from,char *to) { while(*to++=*from++); }[/code] GCC编译没有报错,但运行...

by xuxingyu - C/C++ - 2007-07-04 10:54:02 阅读(1302) 回复(3)

我有几个数组 array0= (1 2 3 6 ) array1= (2 4 1 0 5 9 3 ) array2= (2 4 6 3 1 7 2 1 8) 还有一个变量tmp; 我现在的想法是: while [ $i -lt 0 ] do tmp="array$i" 将tmp变成一个数组,然后对数组元素:em12:进行操作 ==========这个地方该怎么办啊!!! done

by bitzilla - Shell - 2006-08-04 17:19:17 阅读(2897) 回复(9)

a.h头文件 #ifndef A_H_ #define A_H_ class Cd { private: static const int NUM=50; char performers[NUM]; char label[NUM]; int selections; double playtime; public: Cd(const char * s1,const char * s2,int n,double x); Cd(const Cd & d); Cd(); ~Cd(); virtual void Report()const; Cd & operator=(const Cd & d); }; class...

by xueyuyanghf2006 - C/C++ - 2009-05-07 15:32:22 阅读(1160) 回复(3)

不知道项目中开了什么编译选项,我在做指针赋值,例如 char *str = "hello"; 有如下警告: warning: initialization discards qualifiers from pointer target type 试了半天都没解决,请哪位熟悉C标准同志解释一下啊,跪谢!

by zx_wing - C/C++ - 2008-12-29 14:05:15 阅读(1358) 回复(2)

//问题一: char* buf; buf=new char[5]; strcpy(buf,"aaaa"); buf=new char[10]; strcpy(buf,"bbbb"); //请问现在buf占用内存是多少?会是两次new 的累加吗? //问题二: char* buf2; buf2=new char[1]; strcpy(buf2,"1234567890123"); printf("%s\n",buf2); //这段代码执行正常,是意外还是合法? //new char[x] 中的x只是为了检查系统是否有x空间? //请指点迷津,不胜感激!!! [ 本帖最后由 zhaocong94005...

by zhaocong94005 - C/C++ - 2008-07-11 10:43:09 阅读(1261) 回复(7)

#include main() { char *str = "hello"; printf("[%d][%s]\n",strlen(str),str); strcpy(str,"123456789"); printf("[%d][%s]\n",strlen(str),str); } 好像str指向的内容是存放在堆空间上的,怎么解释上面str指向的空间可以随意变长问题,望高人指点。

by rock_jq - C/C++ - 2008-04-26 01:15:05 阅读(2608) 回复(12)