Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

Comparing Strings

Comparing numbers is a very easy task, involving the standard comparison operators (==, <, >, <=, >=), but you cannot compare strings using them. Instead, there is the strncmp() function:

strcmp (string1, string2);

This function returns the value 0 if the two strings are the same and returns a nonzero value otherwise. Normally you'll want to use this as a condition in an if-else statement:

if (strcmp(string1, string2) == 0) {
   // The same!
} else {
   // Different!
}

Our next example creates a tough but functioning guessing game, where the user must guess a three-letter word.

Adjusting for Case

The example is this section—guessing a random three-letter word—is hard enough without trying to adjust for the case of the word. The ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book