CS 102 (Fall '03)
[Schedule]
[Examples] [Programs]
[Notes & Reference]
[Syllabus] [Lab
& TA] [Tests]
[Grades]
We often need to manipulate stored text in C. This can be done using arrays of characters, which are called strings.
Reading multiple words into strings:
- Reading character by character, simply echoing the input
- Reading character by character, storing each word into an array
- Reading a word at a time into an array
arrayStrings.c: using arrays to store strings, reading with %s, overwriting the '\0' at the end of a string. (See also a version tailored for the EECS machines)
encode.c: encoding some input text by a set transposition amount
See in-class notes
arrayptr1.cpp: An example using a pointer with an array
Doing a word lookup in a 2-D array of words, using our own function to compare strings. Same thing, only now a version using strcmp instead of our own function.
A description of some of the string functions.
stringFcns.cpp: A program using various string functions: strcat, strcmp, strcpy, strlen, strstr, strchr, strncpy
Reading a line at a time into an array, then using strtok to parse out each word from the array. (You need to know a bit about pointers to understand this). To understand how strtok works, look at this program that does a similar thing, except we've written the function ourselves.
See string.h in the C standard library functions.
[CS Dept] [UIC] [Prof. Reed]