practical7_2024_PF
practical7_2024_PF
CO Mapping: CO4
Problem Definition: Implement string handling user defined functions - xstrlen(), xstrcpy() and
xstrcmp()
Theory:
Strings in C are represented by arrays of characters. The end of the string is marked with a special
character, the null character. The null or string terminating character is represented by another
character sequence, \0 .
#include <stdio.h>
int main() {
char str1[100], str2[100];
printf("Enter first string: ");
scanf("%s", str1);
printf("Enter second string: ");
scanf("%s", str2);
printf("Length of first string: %d\n", xstrlen(str1));
printf("Length of second string: %d\n", xstrlen(str2));
xstrcpy(str2, str1);
printf("After copying, second string: %s\n", str2);
return 0;
}
Sample input and output
Test case 1:
Enter the string: Programming
Length of string is 11
Test Case 2:
Enter the string1 : Monday
Enter the string2: Monday
Strings are equal.
#include <stdio.h>
#include <string.h>
int main() {
char str[100], rev[100];
int len, i, j;
len = strlen(str);
for (i = 0, j = len - 1; i < len; i++, j--) {
rev[i] = str[j];
}
rev[i] = '\0';
if (strcmp(str, rev) == 0) {
printf("The string is a palindrome.\n");
} else {
printf("The string is not a palindrome.\n");
}
return 0;
}
Sample input and output
Test case 1:
Enter String: MADAM
String is Palindrome
Test case 2:
Enter String: TEST
String is Not a Palindrome
Evaluation:
On time Completion and Knowledge of the topic Implementation and Total (10)
Submission (2) (4) Output (4)