急,程序无错误但结果不对
我是新新手,程序无错误但结果不对请教
我现在大概写了这些,求教啊.
程序代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define FLUSH while (getchar() != '\n') #define MAX_SIZE 256 #define WORD_SIZE 46 void getString (void); void createPiglatinVersion(char *inputStr); int getWord (char *inputStr,char *wordStr, int index); void getPigLatin(char *temp, char *wordStr, int index); bool isVowel(char oneword); void printString(char *inputStr, char *outputStr); bool repeatFcn(void); int main (void) { char inputStr[MAX_SIZE]; char outputStr[MAX_SIZE]; getString(); createPiglatinVersion(inputStr); printString(inputStr, outputStr); system("pause"); return 0; } void getString (void) { char inputStr[MAX_SIZE]; printf("\nEnter a sentence (end with [Enter]):"); fgets(inputStr, sizeof(inputStr), stdin); while (strlen(inputStr)>256) { FLUSH; } } void createPiglatinVersion(char *inputStr) { char outputStr[MAX_SIZE]; char temp[WORD_SIZE]; char wordStr[WORD_SIZE]; int index = 0; int i; for(i=0; i<MAX_SIZE; ++i) { getWord ( inputStr, wordStr, index); getPigLatin( temp, wordStr, index); if (isalpha(*(inputStr+i))== false) outputStr[i]=* (inputStr+i); else { strcpy(outputStr, temp); i=i+index; } } } int getWord (char *inputStr,char *wordStr, int index) { int i; for (i=0;i<WORD_SIZE&&isalpha(inputStr[index]);++i); { wordStr[i]=inputStr[index]; index++; } wordStr[i]='\0'; return index; } void getPigLatin(char *temp, char *wordStr, int index) { char czTemp[WORD_SIZE]; if(isVowel(*wordStr)!=false&&isVowel(*(wordStr+1))) { strcpy(temp, wordStr); // temp[strlen(temp)+1]='\0'; strcat(temp,"ay"); } else if(isVowel(*wordStr)!=false&& isVowel(*wordStr+1)!=false) { strcpy(temp,wordStr+2); czTemp[0] = wordStr[0]; czTemp[1] = wordStr[1]; czTemp[2] = '\0'; strcat(temp, czTemp); //temp[strlen(temp)]=*(--wordStr); //temp[strlen(temp)-1]=*(wordStr-2); //temp[strlen(temp)+1]= '\0'; strcat(temp,"AY"); } else if(isVowel(*wordStr)) { strcpy(temp, wordStr); // temp[strlen(temp)+1]='\0'; strcat(temp,"way"); } } bool isVowel(char oneword) { oneword = toupper(oneword); return ((oneword=='A' || oneword=='E' || oneword=='I' || oneword=='O' || oneword=='U'));//&&(oneword!='Y')); } void printString(char *inputStr, char *outputStr) { printf("The string you entered: %c\n", *inputStr); printf("The string converted to Pig Latin: %c\n", *outputStr); } bool repeatFcn(void) { char check; printf("\nTry another? (y for yes): "); scanf(" %c", &check); if(check=='Y'||check=='y') return true; else return false; }
[ 本帖最后由 ijnbhu8 于 2010-5-4 10:51 编辑 ]