내 작업은 텍스트 파일에서 단어 palindromes를 찾아서 결과 파일에 인쇄하지 않는 것입니다. 결과 파일에는 팔린 드가 아닌 모든 공백과 단어 만 포함되어야합니다. 나는이 프로그램을 2 주 동안 계속해서 일해 왔지만, C에서 전체 newb 인 것처럼이 작업을 올바르게 수행하는 방법을 상상할 수는 없습니다. 또한 Linux 환경에서 작업해야하므로 strrev()와 같은 명령을 사용하여이 시점에서 내 인생을 훨씬 쉽게 만들어 줄 수는 없습니다 ...C에서 단어 palindrome
어쨌든 데이터 파일에는 많은 단어가 포함되어 있습니다. 꽤 많은 공간으로 구분 된 많은 줄.
여기는 작동하지만 어떤 공간에서도 작동하지 않는 프로그램입니다. 필요한 장소에서 프로그램을 검사하는 방법을 모르기 때문입니다.
#include <stdio.h>
#include <string.h>
const int CMAX = 1000;
const int Dydis = 256;
FILE *dataFile;
FILE *resFile;
void palindrome(char *linex);
int main(){
char duom[CMAX], res[CMAX], linex[Dydis];
printf("What's the name of data file? \n");
scanf("%s", duom);
dataFile=fopen(duom, "r");
if (dataFile==NULL){
printf ("Error opening data file \n");
return 0;
};
printf("What's the name of results file? \n");
scanf ("%s", res);
resFile=fopen(res, "w");
if (resFile==NULL){
printf ("Error opening results file \n");
return 0;
};
while (fgets(linex, sizeof(linex), dataFile)) {
palindrome(linex);
}
printf ("all done!");
fclose(dataFile);
fclose(resFile);
}
void palindrome(char *linex){
int i, wordlenght, j;
j = 0;
char *wordie;
const char space[2] = " ";
wordie = strtok(linex, space);
while (wordie != NULL) {
wordlenght = strlen(wordie);
if (wordie[j] == wordie[wordlenght-1]) {
for (i = 0; i < strlen(wordie); i++) {
if (wordie[i] == wordie[wordlenght-1]) {
if (i == strlen(wordie)-1) {
fprintf(resFile,"");
}
wordlenght--;
}
else {
fprintf(resFile,"%s", wordie);
break;
}
}
}
else {
fprintf(resFile,"%s", wordie);
}
wordie = strtok(NULL, space);
}
}
당신은 palindrome을 의미합니까? – Praxeolitic
다각형이란 무엇입니까? – gnasher729
나는 똑같은 방식으로 반응하려했다. 쓰지도 못하는 것에 어떻게 프로그램을 만들 수 있는가? p – yakoudbz