answersLogoWhite

0


Best Answer

I assume the program should be case-sensitive. Here is a code of such program:

#include

#include

int main() {

char str1[100];

char str2[100];

printf("Please enter first string: ");

gets(str1);

printf("Please enter second string: ");

gets(str2);

if (strcmp(str1, str2) == 0) {

printf("Strings are Equal.\n");

} else {

printf("Strings are Not Equal.\n");

}

return 0;

}

Testing:

Please enter first string: A

Please enter second string: A

Strings are Equal.

Please enter first string: a

Please enter second string: A

Strings are Not Equal.

If you want to make not case-sensitive comparing before checking you should make both string in lowercase or uppercase.

Here is how it should look:

#include

#include

#include

void upString(char *str);

int main() {

char str1[100];

char str2[100];

printf("Please enter first string: ");

gets(str1);

printf("Please enter second string: ");

gets(str2);

upString(str1);

upString(str2);

if (strcmp(str1, str2) == 0) {

printf("Strings are Equal.\n");

} else {

printf("Strings are Not Equal.\n");

}

return 0;

}

void upString(char *str) {

register int ind = 0;

while (str[ind]) {

str[ind] = toupper(str[ind]);

ind++;

}

}

Testing:

Please enter first string: aaa

Please enter second string: AAA

Strings are Equal.

Please enter first string: aaa

Please enter second string: aAa

Strings are Equal.

Note: You should not be using gets() function in real-world application. There is no way you can limit number of characters to read thus allowing to overflow buffer. It was used only for example.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

The core of the program is:

if (strcmp (s1, s2)==0) puts ("They are equals");

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to accept two string and display weather they are identical or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program in COBOL to find the largest of N number?

identification division. program-id. greatest. environment division. data division. working-storage section. 77 a pic 999. 77 b pic 999. 77 c pic 999. procedure division. greatest. display "ENTER THE THREE NUMBERS:". accept a. accept b. accept c. if a > b and a > c display a "is greatest" else if b > c display b "is greatest" else display c "is greatest". display " thank you". stop run.


Accept 5 numbers in an array and display it?

Accept 5 numbers in an array and display it.


Write a C program to accept a string from user and display its ascii value and then display sum of all ascii value of strings?

//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include<stdio.h> #include <string.h> int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }


Draw a flowchart to accept 3 numbers and display the largest number?

draw a flowchart to display the first tenth even number


What function enables the user to input information while the program is being executed in c?

The scanf() function is a commonly used function to input information during the execution of a program. scanf() function has its prototype in the stdio.h header file. To accept and display a number: int num; printf("Enter a number: "); scanf("%d",&num); printf("You entered %d",num); To accept and display a character, replace %d with %c and make num a character variable [char]. Plus: gets, fgets, read, fread, getchar, getc, fgetc, getch...

Related questions

Draw a flowchart that will accept radius and display the area of circle?

program that display the area of a circle of a reduce


Write a program in COBOL to find the largest of N number?

identification division. program-id. greatest. environment division. data division. working-storage section. 77 a pic 999. 77 b pic 999. 77 c pic 999. procedure division. greatest. display "ENTER THE THREE NUMBERS:". accept a. accept b. accept c. if a > b and a > c display a "is greatest" else if b > c display b "is greatest" else display c "is greatest". display " thank you". stop run.


Accept 5 numbers in an array and display it?

Accept 5 numbers in an array and display it.


Design an algorithm that will accept a perons name from the screen entered as surname first name separated by a comma Your program is to display the name as first name followed by three blanks?

Design an algorithm that will accept a perons's name from the screen entered as surname, first name, separated by a comma. Your program is to display the name as frist name, followed by three blanks, followed by the surname. -defining diagram -pseudocode algorithm


Write C program for Accept temperature in degree Celsius and display the same in Fahrenheit?

The variable, X, has to undergo the following: X*9÷5+32 [The reverse would be to accept a Fahrenheit temperature: (F-32)*5÷9]


Write a C program to accept a string from user and display its ascii value and then display sum of all ascii value of strings?

//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include<stdio.h> #include <string.h> int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }


What Part of speech accept?

'Acceptable' is an adjective: 'He did not display an acceptable standard of behaviour.'


Draw a flowchart to accept 3 numbers and display the largest number?

draw a flowchart to display the first tenth even number


How do you accept three numbers weather it is equal or unequal?

How_do_you_accept_three_numbers_and_check_weather_the_numbers_are_equal_or_unequal_if_it_is_unequal_find_the_greatest_number_among_them


Draw a flowchart to accept five numbers and display the sum of the numbers?

start, inputbox,inputbox,inputbox,inputbox,inputbox,progresh,display,stop 


What function enables the user to input information while the program is being executed in c?

The scanf() function is a commonly used function to input information during the execution of a program. scanf() function has its prototype in the stdio.h header file. To accept and display a number: int num; printf("Enter a number: "); scanf("%d",&num); printf("You entered %d",num); To accept and display a character, replace %d with %c and make num a character variable [char]. Plus: gets, fgets, read, fread, getchar, getc, fgetc, getch...


What is a program to accept a 3 digit integer and display its octal conversion value?

public class PrintOctal { public static void main(String[] args) { int n = Integer.parseInt(args[0]); System.out.printf("%o\n", n); } }