I have to make a program that takes words input by the user, prints them out, alphabetizes them, and then prints out the alphabetized words. It MUST use functions. I had the code working without functions but now when I try to build it, I get the following errors:
error LNK2019: unresolved external symbol "char __cdecl sortWords(char)" (?sortWords@@YADD@Z) referenced in function _wmain word list.obj
error LNK2019: unresolved external symbol "void __cdecl printWords(char,int)" (?printWords@@YAXDH@Z) referenced in function _wmain word list.obj
error LNK2019: unresolved external symbol "char __cdecl getWords(char)" (?getWords@@YADD@Z) referenced in function _wmain word list.obj
fatal error LNK1120: 3 unresolved externals F:\word list\Debug\word list.exe 1
Here is my code:
And yes, I'm a novice programmer.Code:#include "stdafx.h" #include "string.h" char getWords(char); void printWords(char, int); char sortWords(char); int _tmain(int argc, _TCHAR* argv[]) { #define LETSIZE 15 #define WORSIZE 25 char wordArray[WORSIZE][LETSIZE]; int z, alphaWords = 0; for(z=0; z<WORSIZE; z++) { strcpy(wordArray[z], "\0"); } getWords(wordArray[WORSIZE][LETSIZE]); printWords(wordArray[WORSIZE][LETSIZE], alphaWords); sortWords(wordArray[WORSIZE][LETSIZE]); alphaWords=1; printWords(wordArray[WORSIZE][LETSIZE], alphaWords); return 0; } char getWords(char gWordArray[WORSIZE][LETSIZE]) { char yesNo[2] = "y"; int wordCounter = 0; printf( "Enter a word: "); scanf( "%s", gWordArray[wordCounter]); printf("\n"); if( strlen(gWordArray[wordCounter]) > LETSIZE) { wordCounter = 0; } while( strcmp(yesNo, "y") == 0 && wordCounter < WORSIZE) { wordCounter++; printf( "Do you have more words? yes or no: "); scanf( "%s", yesNo); if(strcmp(yesNo, "y") == 0) { printf( "Enter a word: "); scanf( "%s", gWordArray[wordCounter]); printf("\n"); if( strlen(gWordArray[wordCounter]) > LETSIZE) { wordCounter--; } } } return gWordArray[WORSIZE][LETSIZE]; } void printWords(char prWordArray[WORSIZE][LETSIZE], int alWord) { int y; printf("\n"); for(y = 0; y <= WORSIZE && strcmp(prWordArray[y], "\0")!=0; y++) { printf( "%s \n", prWordArray[y+alWord]); } } char sortWords(char sortWordArray[WORSIZE][LETSIZE]) { char hold[WORSIZE][LETSIZE]; int x, swap, pass; for(pass = 1; pass <= WORSIZE && strcmp(sortWordArray[pass], "\0")!=0; pass++) { swap = 0; for(x = 0; x <= WORSIZE && strcmp(sortWordArray[pass], "\0")!=0; x++) { if(strcmp(sortWordArray[x], sortWordArray[x+1]) > 0) { strcpy(hold[x], sortWordArray[x]); strcpy(sortWordArray[x], sortWordArray[x+1]); strcpy(sortWordArray[x+1], hold[x]); swap = 1; } } if(!swap) break; } return sortWordArray[WORSIZE][LETSIZE]; }
Any help would be greatly appreciated.



LinkBack URL
About LinkBacks



