[問題] 關於引數資料型態問題

看板C_and_CPP (C/C++)作者 (lala)時間15年前 (2011/01/26 21:39), 編輯推噓0(008)
留言8則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) dev c++ 用C語言寫 問題(Question) 想請問大家,有沒有什麼方法 使memoryClean的傳入引數可以接受任何資料型態阿? 多謝指教 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <stdlib.h> #define STRING_SIZE 10 char string[ STRING_SIZE ] = "EXAMPLE"; void memoryClean( char *); int main(void) { printf( "Before clean the memory of string, the content of string is %s\n\n" , string ); memoryClean( string ); printf( "After clean this memory , the content of string is %s\n\n" , string ); system( "pause" ); } void memoryClean(char *memoryAddress ) { int i = 1; for ( i = 1 ; i< STRING_SIZE ; i++ ){ *memoryAddress = 0; memoryAddress++; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.233.180.163

01/26 21:41, , 1F
真是大問題!!!!!!
01/26 21:41, 1F

01/26 21:41, , 2F
void* memoryAddress
01/26 21:41, 2F

01/26 21:44, , 3F
我改成void 可是compiler 不給過
01/26 21:44, 3F

01/26 21:50, , 4F
二樓講的是 void * 而不是 void
01/26 21:50, 4F

01/26 21:53, , 5F
大概會類似這樣: http://nopaste.csie.org/d31ad
01/26 21:53, 5F

01/26 22:02, , 6F
thanks
01/26 22:02, 6F

01/26 22:19, , 7F
有需要自己寫的理由嗎? 不用 memset ?
01/26 22:19, 7F

02/07 11:32, , 8F
ASCII值的 0 不就是 NUL 字元?
02/07 11:32, 8F
文章代碼(AID): #1DG2G8no (C_and_CPP)
文章代碼(AID): #1DG2G8no (C_and_CPP)