programmingsite : code , tutorials and scripts
Navigation

home


ASP
ASP.net
PHP
JavaScript
C
C++
Java
Visual Basic


Resources
code
tutorials
training

Ads
Products

 

 

Comparing 2 strings




Comparing 2 strings

A bit long winded but this shows the strcmp function in action . Ideally you should use a function to cut down on code reuse but I think you get the general idea with this example


#include <stdio.h>
#include <string.h>

char str1[3] = "B0";
char str2[3] = "A9";
char str3[3] = "B1";
char str4[4] = "B0";

int result;

void main()
{

result = strcmp(str1,str2);
if (result == 0)
printf("strings are identical\n");
else if(result < 0)
printf("string1 is less than string 2\n");
else
printf("string1 is greater than string 2\n");

result = strcmp(str2,str1);
if (result == 0)
printf("strings are identical\n");
else if(result < 0)
printf("string1 is less than string 2\n");
else
printf("string1 is greater than string 2\n");

result = strcmp(str1,str4);
if (result == 0)
printf("strings are identical\n");
else if(result < 0)
printf("string1 is less than string 2\n");
else
printf("string1 is greater than string 2\n");
}







Products
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals
Asp Studio 2005
Xtra PHP
Online PHP Script Encoder
Comparison

Links
Make money selling software
Golf resource site
UK price comparison
UK shopping
free articles
free stuff
Gambling resources
Software directory
Health and fitness
Sexy free wallpapers
Hosting resources
ASP site
Beginners PHP
Anime videos
Domain names
Dating site
Programming resources
Dropshippers
Maxi directory
free recipes
Coupons and deals
iPod resources

Ads