這個問題很簡單。我如何將char[]
轉換爲C中的char*
? 我真的很難找到解決方案。所以,你的幫助是高度讚賞:)如何將char []轉換爲C中的char *?
這就是爲什麼我需要這樣的:
sprintf(name,"%c%c%%HACKED%c%c.virus",a,b,c,d); // print a formatted text to string (char[])
strcat(buffer,currentPath); // currentPath is of data type char[]
strcat(buffer,"\\");
strcat(buffer,name); // Now this is where the problem comes in. Since strcat function needs a const char* for it's second argument.
printf("%s",name);
不工作?我的意思是,最後一個'strcat'?我會很驚訝。 'name'是一個真正的char [],是嗎?你沒有包括它的定義。否則,'printf'也會失敗。 –
專業提示:避免使用擴展名.virus命名您的病毒。 – aardvarkk
你知道,大腦激活失敗。我剛看到「string const,不管怎樣」,甚至沒有處理內容的英文含義。也許我應該是*提倡*使用'strcat'和一些粗略的指針數學:-) ++ @ aardvarkk – BRFennPocock