Comparing strings...

Andrew Koenig ark at alice.att.com
Sun Oct 14 23:38:05 AEST 1990


In article <3330 at idunno.Princeton.EDU>, pfalstad at phoenix.Princeton.EDU (Paul John Falstad) writes:

> int strcmp(char *s,char *t)
> {
> 	for (; *s && *s == *t; s++,t++);
> 	return *s-*t;
> }

Whether or not this works depends on your definition of the problem.
If you really want to follow the normal lexical convention that
the null string compares <= anything else, and you're on a machine
on which chars can be negative, then it doesn't work.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list