The display line isnt looping and I cant figure out why...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
int main()
{
// String Storage
char mystring[100];
size_t mystring_reply;
// Format into words
int character_scanner = 0;
int begin_word = 0;
FILE *outfile; // DHH declare a pointer to a file control block.
FILE *infile;
int file_size = 0;
char *buffer;
// Create, open and write to a file**********************
outfile = fopen("Hello_World.txt", "w+");
if (!outfile)
{
printf("File failed to open");
}
fprintf(outfile, "%s", "Hello World. This would happen to be the\n"
"string being tested for whitespace!\n");
fseek(outfile, 0, SEEK_SET);
// ***************************************************************************
#if 0
( DHH long string, multiple adjacent strings are concatenated by the compiler
into one long string. This works as long as there are no % characters in it
because it occupies the position of the format string in the fprintf function call)
A safer implementation would be:
fprintf(outfile, "%s", "Hello World. This would happen to be the string "
"being tested for whitespace!\n");
-or-
fprintf(outfile, "%s\n", "Hello World. This would happen to be the string "
"being tested for whitespace!\n");
#endif
/*
* DHH This version of fgets makes it unnecessary to search for every use of mystring
* to make sure you don't declare it with multiple lengths. I practice, the
* only constants I allow in my code are 1 and 0. Anything else is declared
* as a #define or a variable. It prevents a lot of unnecessary debuging later.
*/
while (fgets(mystring, sizeof mystring, outfile))
{
#if 0
OK, we got a line of input for parsing.
initialize the character scanner to start of line.
#endif
character_scanner = 0;
// loop processing the line.**********************
while (mystring[character_scanner] != NULL) // DHH
{
begin_word = character_scanner;
if (!isspace(mystring[character_scanner]))
{
while (!isspace(mystring[++character_scanner]));
mystring[character_scanner++] = '\0';
}
else
{
begin_word = ++character_scanner;
}
}
}
fclose(outfile);
// ****************************************************
// Loop the display line ******************************
character_scanner = 0;
do
{
printf("%c", mystring[character_scanner]);
character_scanner++;
} while (mystring[character_scanner] != NULL);
// ****************************************************
}