gpt4 book ai didi

c - 前一个数组追加到当前数组

转载 作者:太空宇宙 更新时间:2023-11-04 08:55:18 26 4
gpt4 key购买 nike

前一个数组附加到我想要的数组。我如何获得数组的第一部分? (输出的第一部分)。

int main(void) {
FILE *fIn, *csis;
if (fopen_s(&csis,"csis.txt","w") != 0) {
printf("Failed to open csis.txt for writing.\n");
}
if (fopen_s(&fIn,"congress.txt","r") != 0) {
printf("Failed to open congress.txt for reading.\n");
}
else {
char processTxt[500] , txtUpperCase[500] ;

processFile(fIn, processTxt, txtUpperCase);
printf(txtUpperCase);
fprintf(csis,"%s",txtUpperCase);

cipher(txtUpperCase, 13);

/*outputCode(txtUpperCase);*/

fclose(fIn);
fclose(csis);

}
return 0;
}

void processFile(FILE *fIn, char *processTxt, char *txtUpperCase) {
int i = 0, j = 0;



fgets(processTxt, g_size, fIn);

for (i = 0; i < g_size; i++) {
if (processTxt[i] == '\0')
break;

processTxt[i] = toUpper(processTxt[i]);
}
processTxt[i] = '\0';
for (i = 0; i < g_size; i++) {
if (processTxt[i] == '\0')
break;

if (isUpperCase(processTxt[i])) {
txtUpperCase[j] = processTxt[i];
++j;
}
}
char isLowerCase(char input) {
return (input>= 'a' && input <= 'z');
}

char isUpperCase(char input) {
return (input>= 'A' && input <= 'Z');
}

char toUpper(char input) {
char upperCase = input;

if (isLowerCase(input))
upperCase = (char)((int)input - 32);

return upperCase;
}

输出:CONGRESSSHALLMAKENOLAWRESPECTINGANESTABLISHMENTOFRELIGIONORPROHIBITINGTHEFREEEXERCISETHERE FORABRIDGINGTHEFREEDOMOFSPEECHOROFTHEPRESSORTHERIGHTOFTHEPEOPLEPEACEABLYTOASSEMBLEANDTOPETITIONTHEGOVERNMENTFORAREDRESSOFGRIEVANCESÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌCONGRESS SHALL MAKE NO LAW RESPECTING AN ESTABLISHMENT OF RELIGION, OR PROHIBITING THE FREE EXERCISE THEREOF;或剥夺言论自由或新闻自由;或人民和平集会的权利,以及向政府提出申诉的权利。

最佳答案

您似乎在 txtUpperCase 中缺少终止空字符。您的程序的具体行为未定义; fprintf 将打印它在内存中找到的任何内容,直到到达空字符,甚至超出数组末尾。这些数组似乎在您平台的内存中并排放置,因此它们都被打印出来了。

关于c - 前一个数组追加到当前数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17418531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com