Write a program to compare two strings without using the
strcmp() function

Answer Posted / navy

#include<stdio.h>
#include<conio.h>
void main()
{
char s1[20];
int i, j, len=0, flag=0;
printf("\nEnter any string: ");
gets(s1);
for (i=0; s1[i]!='\0'; i++)
len++;
i = 0;
j = len-1;
while (i < len)
{
if (s1[i] != s1[j])
{
flag = 1;
break;
}
i++;
j--;
}
if (flag == 0)
printf("\nString is palindrome");
else
printf("\nString is not palindrome");
getch();
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an array in c?

581


How are structure passing and returning implemented?

581


How can I get random integers in a certain range?

600


In C language what is a 'dangling pointer'?

626


What the different types of arrays in c?

602






typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1056


we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?

792


Explain how can a program be made to print the line number where an error occurs?

680


What is identifiers in c with examples?

665


Can a pointer be volatile in c?

520


Simplify the program segment if X = B then C ← true else C ← false

2572


Write a program to check armstrong number in c?

621


The purpose of this exercise is to benchmark file writing and reading speed. This exercise is divided into two parts. a). Write a file character by character such that the total file size becomes approximately >10K. After writing close the file handler, open a new stream and read the file character by character. Record both times. Execute this exercise at least 4 times b). Create a buffer capable of storing 100 characters. Now after generating the characters, first store them in the buffer. Once the buffer is filled up, store all the elements in the file. Repeat the process until the total file size becomes approximately >10K.While reading read a while line, store it in buffer and once buffer gets filled up, display the whole buffer. Repeat the exercise at least 4 times with different size of buffer (50, 100, 150 …). Records the times. c). Do an analysis of the differences in times and submit it in class.

1620


How many main () function we can have in a project?

600


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

587