Hello, I have a program in C that deciphers \'caeser text\' into plain english.
ID: 3564676 • Letter: H
Question
Hello, I have a program in C that deciphers 'caeser text' into plain english. In caesar text, the letter given is shifted three letters down. IN this way A becomes D, B becomes E, C becomes F, and so on. When it reaches the end of the alphabet , it wraps back to the beggining (i.e. z becomes c).
Example: Hello = KHOOR
I have completed the code that does the job, but they asked me to use a C string function such as strlen(), strcat(), strcmp() ... Can someone help me incorporate a C function to this existing program?
Much appreciated,
Thank you!
#include
void main()
{
int i=0;
char str[200];
printf("Enter ccaeser text: ");
scanf("%s",str);
while(str[i]!=''){
if(str[i]>=97 && str[i]<=122)
{
str[i]= str[i]-32;
}
if(str[i]>=88)
str[i]=str[i]-26;
str[i]=str[i]+3;
i++;
}
printf("Plain English String is: %s ",str);
}
Explanation / Answer
#include <stdio.h>
#include <string.h>
void main()
{
int i = 0;
char str[200];
printf("Enter caeser text: ");
scanf("%s", str);
int len = strlen(str);
for(i = 0; i < len; i++)
{
if(str[i] >= 97 && str[i] <= 122)
{
str[i] = str[i] - 32;
}
if(str[i] >= 88)
str[i] = str[i] - 26;
str[i] = str[i] + 3;
}
printf("Plain English String is: %s ",str);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.