Showing posts with label comparing string without using library functions. Show all posts
Showing posts with label comparing string without using library functions. Show all posts

Wednesday, August 17, 2011



//WAP TO PRINT ASCII VALUES OF ENTERED CHARACTERS.
#include<conio.h>
#include<stdio.h>
void main()
{
char a[20],ch='Y';
int i,x;
clrscr();
do
{
fflush(stdin);
printf("\n\nENTER THE STRING:");
gets(a);
printf("\n\nENTERED STRING IS");
printf("\n\n");
puts(a);
printf("\n\nASCII VALUES FOR ENTERED STRING IS:");
for(i=0;a[i]!='\0';i++)
{
printf("\n\n");
printf("%d",a[i]);
}
printf("\n\nDO YOU WANT TO CONTINUE?");
scanf("%s",&ch);
}while(ch=='y'||ch=='Y');
printf("\n\nBYE!!!BYE!!!\n\nProgrmmer:ABHISHEK WADHWA");
getch();
}

/*----------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------------

73

74

75

DO YOU WANT TO CONTINUEY


ENTER THE STRING:!@#$%^&*()_+


ENTERED STRING IS

!@#$%^&*()_+


ASCII VALUES FOR ENTERED STRING IS:

33

64

35

36

37

94

38

42

40

41

95

43

DO YOU WANT TO CONTINUE?N


BYE!!!BYE!!!

Progrmmer:ABHISHEK WADHWA
*/

Comparing String without using library functions

//WAP to Compare two strings without using library functions
#include<stdio.h>
int main()
{
   char str1[1000], str2[1000];
   int i, flag=0;

   printf("Enter the First string :\n");
   gets(str1);

   printf("Enter the Second string :\n");
   gets(str2);

   for(i=0;str1[i]!='\0';i++)
   {
  if(str1[i]==str2[i])
      continue;
  else
  {
      flag=1;
      break;
  }
   }
   if(flag==0)
printf("Strings are equal \n");
   else
printf("Strings are not equal \n");
   return 0;
}

/******************OUTPUT***********************
Enter the First string :
abhishek wadhwa
Enter the Second string :
abhishek wadhwa
Strings are equal

*/

Programming the Whole World!