0% found this document useful (0 votes)
47 views

You Will Follow The Same Logic As Lab 7 For Menu Driven Program To Ensure That The User Does Not Enter Wrong Options

The document describes a lab assignment to create a menu-driven C program with 5 string handling options: 1. Copy a string from source to destination using the mystrcpy() function. 2. Compare two strings using the mystrcmp() function and display the results. 3. Concatenate two strings using the mystrcat() function. 4. Check if a string is a palindrome using the isPalindrome() function. 5. Exit the program. The program will prompt the user to enter strings and pass them to functions that emulate standard string functions like strcpy(), strcmp(), strcat() from the string.h library. Header and implementation files mystring.h and my

Uploaded by

AdilMuhammad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

You Will Follow The Same Logic As Lab 7 For Menu Driven Program To Ensure That The User Does Not Enter Wrong Options

The document describes a lab assignment to create a menu-driven C program with 5 string handling options: 1. Copy a string from source to destination using the mystrcpy() function. 2. Compare two strings using the mystrcmp() function and display the results. 3. Concatenate two strings using the mystrcat() function. 4. Check if a string is a palindrome using the isPalindrome() function. 5. Exit the program. The program will prompt the user to enter strings and pass them to functions that emulate standard string functions like strcpy(), strcmp(), strcat() from the string.h library. Header and implementation files mystring.h and my

Uploaded by

AdilMuhammad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Assignment 8

1. For the lab, you will write a menu drive program that will have the following options
1> Copy a string from source to destination.
2> Compare two strings
3> Concatenate two strings.
4> Check if a string is palindrome
5> Exit

You will follow the same logic as Lab 7 for menu driven program to ensure that the
user does not enter wrong options.

2. Create a separate header file called mystring.h and mystring.c(using Visual Studio). The
header file should contain prototypes and the c file should contain definitions of the
following functions.

Option 1 Behaviour:
1. Prompt the user to enter a string into a character array called “src_string” of size 100 in
main using a function called mygets ()
2. Also declare another array of size 100 called “dst_string”.
3. Call the function mystrcpy to copy the src_string into dst_string.
4. Display both strings using a function called myputs ()

a) char* mygets (char* src_string);


This function should emulate the behavior of the gets () function from the string.h library.

b) int mystrcmp (char* str1, char* str2)


This function should emulate the the behavior of strcpy function from string.h

c) char* myputs (char* str)


This function should emulate the behavior of puts () from stdio.h. This function simply returns
the pointer to the string that was passed to it.

Option 2 Behaviour:
1. Prompt the user to enter a string into src_string using mygets ()
2. Prompt the user to enter a string into dst_string using mygets ()
3. Compare the two strings using a function called mystrcmp () described below. This function
adds to the logic of strcmp () from string.h as described below.
4. Display if the src_string is equal, greater than or less than dst_string. If the strings are not
equal, also display the index where the first mismatch occurs using normal printf statements

d) int mystrcmp (char* str1, char* str2, int* fail_index);


This function should emulate the behavior of the strcmp () function from the string.h library. In
addition, this function received a pointer to an integer.
 If strings are equal: store a -1 in memory location pointed by fail_index and return 0
 If string1 is less than string2 (Note we are not comparing pointers but following similar
logic to strcmp), then store the index where the mismatch occurs and return
Negative 1.
 If string1 is greater than string2 (Note we are not comparing pointers but following similar
logic to strcmp), then store the index where the mismatch occurs and return positive 1.

Option 3 Behavior:
1. Prompt the user to enter a string into src_string using mygets ()
2. Prompt the user to enter a string into dst_string using mygets()
3. Append src_string to dst_string using a function mystrcat ()
4. Display both src_string and dst_string using myputs ()

char* mystrcat (char* dst_string, char* src_string)


Appends the src_string to dst_string and returns a pointer to the dst_string. This function
emulates the behavior of strcat () function from string.h

Option 4 Behaviour:
1. Prompt the user to enter a string into src_string.
2. Call a function called isPalindrome () to which you will pass src_string. This function should
check if the passes string is a palindrome or not
3. Display if the string is a palindrome or not using either myputs or printf
Palindromes: A palindrome is a string that can be read the same way in either direction
Examples:

# civic
# dad
# hannah
# kayak
# madam

int isPalindrome(char* str)


return 1 if string is a palindrome else return 0

You might also like