concatenation of two strings

 

EX.NO:3.f                        CONCATENATION OF TWOSTRINGS

 

Aim:

To write a shell program to concatenate two strings.

 

Algorithm:

Step1: Enter into the vi editor and go to the insert mode for entering the code

Step2: Read the first string.

Step3: Read the second string

Step4: Concatenate the two strings

Step5: Enter into the escape mode for the execution of the result and verify the output

 

 

Programcode:

echo “Enter the first string”

readstr1

echo “Enter the second string”

readstr2

echo “The concatenated string is” $str1$str2

 

Sample I/P:

 

Enter the first string: Hello

Enter the second string: World

 

Sample O/P:

 

The concatenated string is HelloWorld

 

Result:

 

Thus the shell program to concatenate two strings is executed and output is verified successfully.

 

VIVA-VOCE QUESTIONS:

 

1. What is string concatenation?

2. Which function is used to join two strings?

3. What does Strcat do in C?

 

 

 

 

 

 

EX.NO:3.g                             COMPARISON OF TWOSTRINGS

 

Aim:

To write a shell program to compare the two strings.

 

Algorithm:

 

Step1: Enter into the vi editor and go to the insert mode for entering the code Step2: Read the first string.

Step3: Read the second string

Step4: Compare the two strings using the if loop

Step5: If the condition satisfies then print that two strings are equal else print two strings are not equal.

Step6: Enter into the escape mode for the execution of the result and verify the output.

 

 

Programcode:

 

echo “Enter first string”

readstr1

echo “Enter second string”

readstr2

 if [ $str1 = $str2 ]

 then

echo “The two strings are equal

else

echo “The two strings are not equal”

 fi

 

 

 

 

 

 

 

Sample I/P:1

Enter first string: hai

Enter second string: hai

Sample O/P:1

The two strings are equal

Sample I/P:2

Enter first string: hai

Enter second string: cse

Sample O/P:2

The two strings are not equal

 

 

Result:

Thus the shell program to compare the two strings is executed and output is verified successfully.

 

VIVA-VOCE QUESTIONS:

 

1. How to compare two strins in c?

2. What is stricmp() in C?

 

Comments

Popular posts from this blog

1.Import and Export(How to read csv file using manualvfunction)

How to became a junior Engineer

Pima Dataset