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

C programming must be compiled with gcc -Wall 1. (60 points) Joe wants a way to

ID: 3588928 • Letter: C

Question

C programming must be compiled with gcc -Wall

1. (60 points) Joe wants a way to encode his notes he passes in class so his teacher cannot read them. Write a program that encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i with the letter with alphabetical position 25 – i. For example, letter a is at position 0 and after encoding it becomes letter z (position 25). Letter m is at position 12, it becomes letter n (25 – 12 = 13) after encoding. For example,

Your program should include the following function:

void convert(char *s1, char *s2);
The function expects s1 to point to a string containing the input as a string and stores

the output to the string pointed by s2.

1) Name your program notes.c.
2) Assume input is no longer than 1000 characters.
3) The convert function should use pointer arithmetic (instead of array

subscripting). In other words, eliminate the loop index variables and all use of

the [] operator in the function.

4) To read a line of text, use the read_line function (the pointer version) in the lecture notes.

Explanation / Answer

#include <stdio.h>

void convert(char *s1, char *s2);

int main()
{
char s1[] = "at the cafeteria";
char s2[1000];
convert(s1, s2);
printf("Input: %s ", s1);
printf("Output: %s ", s2);
return 0;
}

void convert(char *s1, char *s2) {
while(*s1 != '') {
if (*s1 != ' ')
*s2 = 'a' + (25 - (*s1 -'a'));
else
*s2 = *s1;
*s1++;
*s2++;
}
}

I have used my own code to demonstrate that convert function work as you haven't provided required code and your question mainly ask for this code only.

Sampe execution:

Input: at the cafeteria
Output: zg gsv xzuvgvirz