我試圖通過硬編碼打印輸出,但我得到一個錯誤,因爲我給出的參數是類型char**
和格式在printf
中指定了char *類型。格式指定類型'char *',但參數具有類型'char **'
此外,還有四行代碼,我不明白(請參閱下面的代碼中的代碼註釋),所以這將是真正有用的是有人解釋代碼塊。在你的代碼
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void inputParsing(char *src, char *end, char *destU, char *destP) {
int x = 0;
for(; src != end; src++){
if((*src != '+') && x==0) {
*destU = *src;
destU++;
}
else if((*src != '+') && x==1){
*destP = *src;
destP++;
}
else {
x = 1;
}
}
*destU = ' '; //What does this line do?
*destP = ' '; //What does this line do?
*++destU = '0'; //What does this line do?
*++destP = '0'; //What does this line do?
printf("%s\n",&destU);
printf("%s\n",&destP);
}
void inputStoring() {
char inputArray[200];
char usernameArray[200];
char passwordArray[200];
//int n = atoi(getenv("CONTENT_LENGTH"));
//fgets(inputArray, n+1, stdin);
strcpy(inputArray, "gaming+koko");
int n = strlen(inputArray);
inputParsing(inputArray, inputArray + n, usernameArray, passwordArray); //inputArray+n is referencing the array cell that contains the last inputted character.
}
int main(void) {
inputStoring();
}
此代碼從何而來?它的目的是什麼? (不知道這一點,我們只能推測個別行的目的...) –
我認爲你會對你標記的那兩行*之後更感興趣,因爲它們是那些在程序中調用*未定義的行爲*。標記行只是使用指針解引用操作符將來自調用者的提供緩衝區中的單個字符存儲起來。 (使用第二對增加存儲位置)。 – WhozCraig
@OliCharlesworth - 我寫了這段代碼,通過POST方法從網站獲取輸入。所以基本上我將輸入存儲在inputArray中,然後調用方法inputParsing來分隔用戶名和密碼並將它們存儲在兩個不同的數組中。 – user1836292