Project 5 Implementation of fillwords

Project 5 Implementation of fillwords - exit(1); } const...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <fstream> #include <cstring> #include <cstdlib> #include <cctype> using namespace std; const int MINWORDLENGTH = 4; const int MAXWORDLENGTH = 6; void fillWords(char words[][MAXWORDLENGTH+1], int maxwords, { //********************* //*** On a Windows system, if you replace the filename with the name //*** of some other file, use / in the string instead of \ (e.g., //*** "C:/CS31/Project5/mywordfile.txt"). const char filename[] = "Z:/words.txt"; ifstream wordfile(filename); if ( ! wordfile) { cout << "Cannot open " << filename << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: exit(1); } const int LINELIMIT = 10000; char line[LINELIMIT]; num = 0; while (wordfile.getline(line, LINELIMIT)) { if (num == maxwords) { cout << "Using only the first " << num << " words from " << filename << endl; break; } int k; for (k = 0; islower(line[k]); k++) ; // The following two lines fix things for non-Windows users if (line[k] == '\r') line[k] = '\0'; if (line[k] == '\0' && k >= MINWORDLENGTH && k <= MAXWORDLENGTH) { strcpy(words[num], line); num++; } } }...
View Full Document

This note was uploaded on 11/07/2009 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 2

Project 5 Implementation of fillwords - exit(1); } const...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online