我是來自Java的C的新手。只是解釋我爲什麼這樣的:C++不能更改字符數組中的元素
text[0] = 'a';
是不可能的,我的程序只是崩潰。
#include "caesarHead.h"
#include <limits.h>
int main(void) {
\t caesar("Hello this is a sample text", 12);
\t printf("\n\n");
}
void caesar(char text[], char offset) {
\t int i = 0;
\t text[0] = 'a';
\t char *p = text;
\t for (p; *p != '\0'; p++) { \t
\t \t \t
\t \t printf("String: %c \n", text[i]);
\t \t printf("Ascii: %i \n", (int)text[i]);
\t \t i++;
\t }
}
「我是C新手」 - spo爲什麼你的標題和標籤會說「C++」? – Olaf
使用C標記或std :: string或者如果你的編譯器已經支持它std :: string_view。 – 2017-07-06 21:28:11