ok so the assignment is for the user to enter some ........ and then the program prints it out, then pritns the number of characters, words, lines, etc. I'm trying to modify the first function 'getstring' so it sends the string back into main to get printed. My first question is at the end what does this mean:
Code:
string[count] = '\0';
? well what does '\0' mean? my second question is how can i modify that function to print int he main? changing the main function isn't allowed.
Code:
#include <stdio.h>
#define SIZE 200
void getString( char* );
void parseString( char*, int*, int*, int* );
int isWhiteSpace( char );
int main()
{
char string[SIZE]; // The string that stores the users input
int lines = 0; // The total number of lines the user inputs
int words = 0; // The total number of words the user inputs
int chars = 0; // The total number of chars the user inputs
// Get input from the user and put it in "string"
getString( string );
// Parse the string and count the # of lines, words and characters
parseString( string, &lines, &words, &chars );
// Print the text that the user entered
printf( "\n\nHere is the text you entered:\n" );
printf( "%s", string );
// Print the number of lines, words and characters
printf( "\n\nLines: %d\n", lines );
printf( "Words: %d\n", words );
printf( "Chars: %d\n", chars );
return 0;
}
/**
* This function gets input from the user
* and stores it in the string which is
* passed into the function.
*/
void getString( char *string )
{
char c;
int count = 0;
while( (c = getchar()) != '^' && count < SIZE-1)
{
string[count++] = c;
}
string[count] = '\0';
}
/**
* This function iterates through "string"
* and counts the number of lines, words and
* chars. The totals are stored at the locations
* that are referred to by the three pointers
* to integers.
*/
void parseString( char *string, int *lines_ptr, int *words_ptr, int *chars_ptr )
{
/**
* Suggestion: Use two pointers to iterate through
* the string and find where words begin and calculate
* all the totals.
*
char *prev; // Previous location in string
char *curr; // Current location in string
*/
}