Code for rotate.c (in C not C++): /* rotate.c : map a->b, b->, ... z->a */ #incl
ID: 3861794 • Letter: C
Question
Code for rotate.c (in C not C++):
/* rotate.c : map a->b, b->, ... z->a */
#include <stdio.h>
#include <ctype.h>
#include <termios.h>
int main() {
int c;
struct termios original_mode;
struct termios ttystate;
// record initial terminal settings for later use
tcgetattr(0, &original_mode);
// change settings
tcgetattr( 0, &ttystate); /* read curr. setting */
ttystate.c_lflag &= ~ICANON; /* no buffering */
ttystate.c_cc[VMIN] = 1; /* get 1 char at a time */
tcsetattr( 0 , TCSANOW, &ttystate); /* install settings */
while ( (c=getchar() ) != EOF) {
if (c=='z')
c = 'a';
else if (islower(c))
c++;
putchar(c);
}
// restore initial terminal settings
tcsetattr(0, TCSANOW, &original_mode);
return 0;
}
Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#include <termios.h>
int main() {
int c;
struct termios original_mode;
struct termios ttystate;
// record initial terminal settings for later use
tcgetattr(0, &original_mode);
// change settings
tcgetattr( 0, &ttystate); /* read curr. setting */
ttystate.c_lflag &= ~ICANON; /* no buffering */
ttystate.c_cc[VMIN] = 1; /* get 1 char at a time */
tcsetattr( 0 , TCSANOW, &ttystate); /* install settings */
while ( (c=getchar() ) != EOF) {
if (c=='z')
c = 'a';
else if (islower(c))
c++;
putchar(c);
}
// restore initial terminal settings
tcsetattr(0, TCSANOW, &original_mode);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.