Objectives:

  • To demonstrate the use of the C language to solve simple computational problems.
  • To illustrate the ability to use proper C language syntax to implement algorithms.
  • To demonstrate ability to analyse a practical problem and come up with a software solution.

Task:

With the help of an IDE and a debugger, use the C language tool to develop a program as described below. Students should demonstrate their ability to analyse and translate a real life problem into a software algorithm by using the C language as a tool. The use of proper programming techniques to come up with an efficient code that meet the requirements is required. The expected code should be error free and ready to be used by any computer user with little difficulties.

Background:

The C language is a compiled computer language with the advantage of being suitable for developing low level software as well as high level software. In this experiment, students are asked to develop a C program consisting of a few functions that carry out the task of string manipulations. String manipulation functions are commonly used in big text processing applications such as word processors, text editors, etc. On a Google search page, for example, you can enter a sentence in the search field, then later on you can edit that sentence and add more words in the middle and do the search again. Those string manipulation facilities calls upon applications, such as Google search web page to have strong string manipulation capabilities in order to make the interface very user friendly. In this assignment you will be developing a program that will mimic some of those string manipulation capabilities.

Equipment:

A PC running Windows and using Dev++ C/C++ IDE environment installed. You are expected to use the debugging tools available on the IDE to develop a working program that is free from bugs.

Procedure:

In this program you need to develop a complete C program that consists of a main program and three functions, StringInsert(), 'Stringclean(),' and StringCase()

-StringInsert() function should have the following capabilities:

1.Receives two strings S1, and S2, and an integer 'pos'. The maximum length of string S1 and S2 should not be greater than 20 characters.

2.Decide which string is the longest among S1 and S2

3.Insert the shortest string inside the longest string at a position specified by 'pos' and then add an extra space right after the position of S2. For example if the function receives those values: S1= "good sir", S2=morning, and pos= 6 then since S1 is longer than S2 then S1 becomes good morning sir (note:observe the extra space between morning and sir).

4.The function should return an integer value of either 1 or 2 indicating which string is the longer S1, or S2. If S1 is longer the return value is 1 otherwise the return value is 2 (meaning S2 is bigger).

5.In case that both strings have the same value for length then any one string can be used as the longest string.

6.The function should always check the validity of the integer 'pos' for a right value. The right value should be bigger than 0 and less or equal the length of the longer string (0 < pos <= length of longer string), and if it is found not to be so the function should print an error message and returns 0.

-Stringclean() function does the task of removing all extra spaces from a string leaving only one space between the words. It should work as follows:

1.Receives a string as input parameter.

2.Remove any two consecutive spaces from the received string.

3.Repeat step 2 until one space is left between the words.

4.Return the new cleaned string.

-StringCase() function does the task of converting the first character of each word in a string into upper case as follows:

1.Receives a string as input parameter.

2.Search from the beginning of the string and locate the first word, convert the first character to upper case, then move on to the next word and do the same thing until the last word in the string. For example, if the string's original content is " this Is a sentence" then the output string from this function is: This Is A Sentence. (note the modifications in red).

-The main program works as follows:

1.Asks the user to input two strings and an integer.

2.The program should then call StringInsert() function with those three values as input parameters and then print the returned string.

3.The program should then call Stringclean() function passing it the resultant string from the previous call (the returned string from function StringInsert) and then prints the returned string.

4.The program then calls function 'StringCase()', again passing it the resultant string from the previous call, and then prints the resultant string.

Note: It is important you provide proper commentaries on the source code so that it can be clearly understood.

5.If your functions are to be used as scripts in a web page. Discuss the possible techniques that will need to be done

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.