C - strcmp()-string comparison

<<Previous

Next >>





This function compares two strings and returns an integer value.

Syntax:
	int strcmp(const char *s1,const char *s2);

It returns zero value if both strings are same or it returns negative value if string s1 is less than s2 or it returns positive value if s1 is greater than s2. It can perform case sensitive comparison. Suppose if two strings are same but in different case, then it will return non-zero value as result. For example: HELLO is not same as hello.

Following is an example program using strcmp()

#include<stdio.h>

#include<string.h>


main()
{
  char first[]={’W’,‘E’,‘L’,‘C’, ‘O’,‘M’,‘E’};
  char second[];
  int result;

  clrscr();
  printf(" The first string is %s ",first);
  printf(" \n Enter the second string ");
  scanf(" %s ",&second);

  result = strcmp(first,second );
  printf(" \n The comparison result %d ",result);
  return(0);
}

Output:

The first string is WELCOME
Enter the second string WELCOME
The comparison result 0

<< Previous

Next >>







C - strcmp()-string comparison

<<Previous

Next >>





This function compares two strings and returns an integer value.

Syntax:
	int strcmp(const char *s1,const char *s2);

It returns zero value if both strings are same or it returns negative value if string s1 is less than s2 or it returns positive value if s1 is greater than s2. It can perform case sensitive comparison. Suppose if two strings are same but in different case, then it will return non-zero value as result. For example: HELLO is not same as hello.

Following is an example program using strcmp()

#include<stdio.h>

#include<string.h>


main()
{
  char first[]={’W’,‘E’,‘L’,‘C’, ‘O’,‘M’,‘E’};
  char second[];
  int result;

  clrscr();
  printf(" The first string is %s ",first);
  printf(" \n Enter the second string ");
  scanf(" %s ",&second);

  result = strcmp(first,second );
  printf(" \n The comparison result %d ",result);
  return(0);
}

Output:

The first string is WELCOME
Enter the second string WELCOME
The comparison result 0

<< Previous

Next >>







Learn about Hashing and Hash table

Learn Expression Tree

OS Kernel Architecture

OS Arcitecture of Windows, Linux and MacOS

Learn OS scheduling Algorithms