CSC 270 - Survey of Programming Languages

Assignment #4c - Replacing "is" with "was ".

Due Wednesday, September 20, 2017

Using the string methods that we have learned so far, write a program that will allow the user to type in line of text until the user types in the phrase "The end" on a line by itself. The program will replace every occurrence of "is" with the string "was" and count the number of changes made.

You may choose to use c-style strings or the string class. You can find them describes in C Lecture #4.

You may find the following functions useful; you may use them in the assignment (Remember to put their prototypes at the top of the program):

int     strindex(char s[], char t[])
{
  int     i, j, k;

  for (i = 0; s[i] != '\0'; i++)  {
	for (j = i, k = 0;
			t[k] != '\0' && s[j] == t[k];
			j++, k++)
		;
		
	if (k > 0 && t[k] == '\0')
		return(i);
  }
  return(-1);
}

void	substring(char t[], char s[], int start, int len)	{
	int	i, j, k;

	for (i = start, j = 0; j < len && s[i] != '\0'; i++, j++)
		t[j] = s[i];
	t[j] = '\0';
}

[Back to the Assignments List]