Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAMMING NOT C++ Write the following functions, consistent with the prototy

ID: 3680267 • Letter: C

Question

C PROGRAMMING NOT C++

Write the following functions, consistent with the prototypes shown: 1. int strlen (char s) Given a string, return the number of characters in the string, NOT INCLUDING the null at the end 2. char strcpy (char s 1, char s2) i The function will copy the string s2 into the string s1. Note the function returns the address of the string 3. char strcat (char s1, char s2) The function concatenates the string s2 into the end of string s1. lf s1 is "Hello and s2 is "World" before, after calling strcat, s1 will be "Hello World" Important o Do NOT use the C library routines o Do implement the functions EXACTLY as prototyped (i.e., no extra parameters, no fewer parameters, etc.) o You may use the functions as building blocks Write main() functions to test and debug each of the above string functions, using gets() and puts() for string input and output as follows A. To demonstrate strlen(), input your first name using gets() and use printf to print the string followed by the number of characters in the string. An input of "Ken" would print 3. Show this with 3 different string input examples B. To demonstrate strcpy0, input your first name using gets (s1) and use strcpy() to copy it to a second string, s2 and print both strings with puts(). So an input of "Ken" would print: "string Ken string2 Ken C. To demonstrate strcat0, use gets() to input your first name, last name, and D as three separate strings, print them out, one per line, concatenate the three strings, and then use puts() to print out Hello followed by your name and ID. If the three input strings entered are "Ken" "Arnold" and "876543210", then it should print ken Arnold 8765 43 210 Hello Ken Arnold 87 654 3210

Explanation / Answer

//String1 is first name, String2 is last name and String3 is the ID

#include<stdio.h>
#include<conio.h>
#include<string.h>
int slen(char* s1);
char* scpy(char* s1,char* s2);
char* scat(char* s1,char* s2);
void main()
{
char s1[20],s2[20],s3[20];
clrscr();
printf("Enter your first name:");
gets(s1);
printf("Enter your last name:");
gets(s2);
printf("Enter your ID:");
gets(s3);
printf("Length of string1=%d ",slen(s1));
scpy(s1,s2);
printf(%s %s %s ",s1,s2,s3);
printf("Hello ");
scat(s1,s2);
printf("%S",s3);
getch();

int slen(char* s1) // return number of characters in first name
{
int a;
a=strlen(s1);
return a;
}

char* scpy(char* s1,char* s2) //copy string s1 to s2 and then print
{
s2=s1;
printf("String1=%s String2=%s ",s1,s2);
return 0;
}

char* scat(char* s1,char* s2) //concantenates manually
{
printf("%s %s",s1,s2);// or can use predefined function:   strcat(s1,s2);
return 0;
}