Um guys....this is getting Slashdoty....I'm a programmer by profession but come on...you are all NERDS!!!!
// Eliminate deprecation warnings for the older, less secure functions // Needed for Microsoft Visual Studio 2005 (Visual C++ Version 8) #define _CRT_SECURE_NO_DEPRECATE // Compiler Includes #include <stdio.h> // Using Directives & Declarations // Project Includes // Constants #define UPPER_MAX 'Z' #define UPPER_MIN 'A' #define LOWER_MAX 'z' #define LOWER_MIN 'a' #define NUM_MAX '9' #define NUM_MIN '0' #define MAX_STRING_LENGTH 81 #define FALSE 0 #define TRUE 1 #define SPACE ' ' #define TAB '\t' #define EOL '\n' #define PERIOD '.' #define EXCLAMATION '!' #define QUESTION '?' // User Defined Types // Function Prototypes //////////////////////////////////////////////////////////////////////////////// // // Function Name : main // // Originated : October 20, 2008 // // Abstract : Given an input file name from the user, Count the total // number of words and sentances // // Parameters : None // // Return Value : error code - zero means no errors // // Misc. I/O : na // // Revisions : // //////////////////////////////////////////////////////////////////////////////// int main (void) { // Local Variables char inputFilename[MAX_STRING_LENGTH]; FILE *inputFileHandle = NULL; int endOfFileResult = 0; char currentCharacter = '\0'; char lastChar = '\0'; char last2Char = '\0'; int wordCount = 0; int inAWord = FALSE; int sentenceCount = 0; int inASentence = FALSE; int isASpaceTabOrEol = FALSE; int isATerminator = FALSE; // Begin // Prompt user for input file name printf("Enter input file name: "); // Get input file name gets(inputFilename); // Open input file inputFileHandle = fopen(inputFilename, "r"); // IF input file found (file opened successfully) if (inputFileHandle != NULL) { // Read first character endOfFileResult = fscanf(inputFileHandle, "%c", ¤tCharacter); // WHILE not end of file while (endOfFileResult != EOF) { if (currentCharacter >= UPPER_MIN && currentCharacter <= UPPER_MAX || currentCharacter >= LOWER_MIN && currentCharacter <= LOWER_MAX || currentCharacter >= NUM_MIN && currentCharacter <= NUM_MAX) { inAWord = TRUE; } // end if isASpaceTabOrEol = currentCharacter == SPACE || currentCharacter == TAB || currentCharacter == EOL; if (inAWord && isASpaceTabOrEol) { wordCount++; inAWord = FALSE; } // end if // Read next character endOfFileResult = fscanf(inputFileHandle, "%c", ¤tCharacter); } // end while // Rewind input file (SECOND PASS) void rewind(inputFileHandle); <<<ERROR ONE!!! missing ; before type // IF input file found (file opened successfully) if (inputFileHandle != NULL) { // Read first character endOfFileResult = fscanf(inputFileHandle, "%c", ¤tCharacter); // WHILE not end of file while (endOfFileResult != EOF) { if (currentCharacter >= UPPER_MIN && currentCharacter <= UPPER_MAX || currentCharacter >= NUM_MIN && currentCharacter <= NUM_MAX) { inASentence = TRUE; } // end if isATerminator = currentCharacter == PERIOD || currentCharacter == EXCLAMATION || <<<ERROR TWO!!! to many characters currentCharacter == QUESTION; isASpaceTabOrEol = currentCharacter == ' ' || currentCharacter == '\t' || <<<ERROR THREE!!! to many characters currentCharacter == '\n'; if (inASentence && currentCharacter == ' ' && lastChar == 'isASpaceTaborEol' && last2Char == 'isATermitator'); sentenceCount++; inASentence = FALSE; last2Char = lastChar; lastChar = currentCharacter; } // end if // Read next character endOfFileResult = fscanf(inputFileHandle, "%c", ¤tCharacter); } // end while // Close input file fclose(inputFileHandle); // Display output printf("Number of words found is %d!\n", wordCount); printf("Number of sentences found is %d!\n", sentenceCount); } // end if else { // Display error message (input file not found) printf("ERROR: Input file name %s was not found!\n", inputFilename); } // end else return 0; } // end function main // end file program5.c This is what I have so far I cannot test it out yet will not let me build it I have 3 errors Error 1 error C2143: syntax error : missing ';' before 'type' c:\users\dustin geiselman\documents\visual studio 2005\projects\ecet 264 projects\program5.c 136 Error 2 error C2015: too many characters in constant c:\users\dustin geiselman\documents\visual studio 2005\projects\ecet 264 projects\program5.c 164 Error 3 error C2015: too many characters in constant c:\users\dustin geiselman\documents\visual studio 2005\projects\ecet 264 projects\program5.c 164
GN, it depends on the read function used. gets() and getc() differ, for example, in that one does character-based operations with functions that read characters, and string-based operations with functions that read strings... and strings are presumed to end with crlf (which are replaced with \0) in a stream, whereas in character ops, those would just be two chars that weren't EOF. Dustin, if (inASentence && currentCharacter == ' ' && lastChar == 'isASpaceTaborEol' && last2Char == 'isATermitator'); is a bad if statement. I think you meant to end with an open brace... isATerminator is misspelled, etc... Anyway, I think you really ought to use your college's resources (TA, lab help, professor help, tutor/mentors...) instead of us.