Friday 20, July 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
 
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 : 5599
   
pointer and there uses in c
Example code for pointer and there uses in c language....more »
Category : C Programs Hits : 1988
   
Print fibonacci series using c language
Here is a c language program which will take number of terms as input from user and prints the fibonacci series using c language loops....more »
Category : C Programs Hits : 3685
   
concatenate two strings c language
Here is an example code to concatenate two strings using clanguage....more »
Category : C Programs Hits : 3349
   
Find Factorials using Recursion in c
This c program will use recursive function and calculate the factorial of given number....more »
Category : C Programs Hits : 1881
   
   
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 Introduction to Object-Oriented Programming Using C++  Ebook Introduction to Object-Oriented Programming Using C++
   
Download 	A Beginners C++ Ebook A Beginners C++
   
Download List Building Ebook List Building
   
Download Blog for Dollar Ebook Blog for Dollar
   
Download Targeted Cyber Attacks  The Dangers Faced by your Corporate Network Ebook Targeted Cyber Attacks The Dangers Faced by your Corporate Network
   
Studiesinn.com 2018 All Rights Reserved.