1. Write the statements to read two strings s1 and s2 from user input and output
ID: 3708885 • Letter: 1
Question
1. Write the statements to read two strings s1 and s2 from user input and output the one that comes later in the lexicographic order.
2. Declare (not define) a function called longer that takes two strings as parameters (without using array notation) and returns the longer string.
3. Write a function removeSpaces that remove all space characters from a given string s1 and stores the result in a second string s2. Your function should have the following prototype:
void removeSpaces (char *s1, char *s2);
4. Complete the code below to print the second to last character of the string mystring.
char mystring[200];
scanf(“%s”, mystring); /* initialize from standard input */
Explanation / Answer
Hi Dear, Please find my implementation.
Q1.
char s1[100], s2[100];
printf("Enter first string: ");
scanf("%s", s1);
scanf("%s", s2);
if(strcpy(s1, s2) < 0) {
printf("%s ", s2);
}else{
printf("%s ", s1);
}
Q2.
char *longer(char *s1, char *s2);
Q3.
void removeSpaces(char *s1, char *s2) {
int i= 0, k = 0;
while(s1[i] != '') {
if(s1[i] != ' ') {
s2[k] = s1[i];
k++;
}
i++;
}
s2[k] = '';
}
Q4.
char mystring[200];
scanf("%s", mystring);
int len = strlen(mystring)-1;
printf("%c", mystring[len-1]);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.