[英]Is curly braces needed in initialization of an array of pointers in structure?
[英]Array initialization needs curly braces
我一直在嘗試使此代碼能夠使用ROT13加密來加密*char[]
指針數組。 幾個問題:
這是我的代碼:
void rot13(int numlines, char * text[]){
//printf("%s\n", text);
//char encrypted[length(text)];
for (int i=0; text[i]>='\0'; i++){
if (*text[i]>='A' && *text[i]<='Z'){
*text[i]=(((*text[i]-'A')+13)%26 + 'A');
}else if(*text[i]>='a' && *text[i]<='z'){
*text[i]=(((*text[i]-'a')+13)%26 + 'a');
}
}
printf ("%d\n ",*text);
}
int main(){
char text1[]="parliament";
char * text[]=&text1;
rot13(10, text);
}
以char * text[]=&text1;
, text
被聲明為指向char
的指針的數組。 因此是數組類型。 如果不使用花括號,則無法對其進行初始化(例外:字符串文字)。 最好將其聲明為指向char的指針
char **text = &text1;
您應注意, main
和function參數中的聲明char * text[]
不相同。 當聲明為函數參數時, char * text[]
等同於char **text
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.