Friday 20, April 2018
Welcome Guest, Register | Login  
      Home       Tutorials       Free Ebooks       Free Scripts       Tech News       Articles       About Us       Blog        Forum

  Compare two strings using c

This program will input two strings and compare them. It will show both strings are equal, first string is greater than second or first string is less than second.
Cut & Paste Script
#include<stdio.h>
#include<conio.h>
void main()
{
    int count1=0,count2=0,flag=0,i;
    char str1[10],str2[10];
    clrscr();
    puts("Enter a string:");
    gets(str1);
    puts("Enter another string:");
    gets(str2);     
    while (str1[count1]!='\0')
        count1++;

    while (str2[count2]!='\0')
        count2++;
    i=0;
    while ( (i < count1) && (i < count2))
    {
        if (str1[i] == str2[i])
        {
            i++;
            continue;
        }
        if (str1[i]<str2[i])
        {
            flag = -1;
            break;
        }
        if (str1[i] > str2[i])
        {
            flag = 1;
            break;
        }
    }
    if (flag==0)
        printf("Both strings are equal\n");
    if (flag==1)
        printf("String 1 is greater than string 2\n", str1, str2);
    if (flag == -1)
        printf("String 1 is less than string 2\n", str1, str2);
    getch();
}
 
   
     RELATED SCRIPTS
 
C program to join two strings without using strcat
This c language program will join two strings without using strcat string function....more »
Category : C Programs Hits : 2258
   
Check number is prime or not using c

Here is a code example to check the number is prime or not a prime number. It will input number from user. If number is prime, it will print "Number is prime" on screen and if number is not prime it will print "Number is not prime".

...more »
Category : C Programs Hits : 5574
   
Bubble sort using c language
This program will sort an array using bubble sort in c language. c program for bubble sort, bubble sort in c, sorting an array using bubble sort in c language....more »
Category : C Programs Hits : 3766
   
Convert decimal number to binary number in c
This c language program will input an integer in decimal numbers system and convert it to binary numbers system. Decimal to Binary Conversion, Convert from decimal to binary using c language....more »
Category : C Programs Hits : 4664
   
Check the given year is leap or not using c
This program will input a year and check whether it is a leap year or not....more »
Category : C Programs Hits : 3520
   
   
SCRIPT CATEGORIES
 
  C Programs
C Programs scripts
  C++ Programs
C++ Programs scripts
  Java Programs
Java Programs scripts
  JavaScript Examples
JavaScript Examples scripts
  PHP Examples
PHP Examples scripts
  VBScript Examples
VBScript Examples scripts
 
 
 
POPULAR E-BOOKS
 
Download Prospecting and the Sales Pitch Ebook Prospecting and the Sales Pitch
   
Download Dear Employee Your Job Sucks Ebook Dear Employee Your Job Sucks
   
Download Creating Wealth Boot Camp Ebook Creating Wealth Boot Camp
   
Download Glossary of Search Engine Ranking Term Ebook Glossary of Search Engine Ranking Term
   
Download Domain Name Whitepaper  Making Money with Domains  Ebook Domain Name Whitepaper Making Money with Domains
   
Studiesinn.com 2018 All Rights Reserved.