CS 101 Lecture Notes
Week Seven, Monday/Tuesday: Strings
Program Example: Fox Test
/* Chapter 6 string program example */
/* Copyright 1999 by Rick Wagner, all rights reserved. */
#include <stdio.h>
#include <string.h>
void about();
void foxTest();
void main()
{
about();
foxTest();
}
void about()
{
puts("This program will count the letters in a sentence.");
puts("");
}
void foxTest()
{
int i = 0;
int j = 0;
int iLength = 0;
char cpFoxTest[] = "the quick brown fox jumped over the lazy dog's back.";
char cLetter = 0;
iLength = strlen(cpFoxTest);
for (i = 97; i <= 122; i++)
{
for (j = 0; j < iLength; j++)
{
if (i == cpFoxTest[j])
{
cLetter = (char) i;
printf("%c", cLetter);
}
}
if (i == 109)
{
printf("\n");
}
else
{
printf(", ");
}
}
printf("\n\n");
}
/*
Sample output:
This program will count the letters in a sentence.
aa, bb, cc, dd, eeee, f, g, hh, i, j, kk, l, m
n, oooo, p, q, rr, s, tt, uu, v, w, x, y, z,
*/
This page established February 28, 1999; last updated March 5, 1999.