Reverse String 1.0

main.cpp

 1 #include <iostream>
 2 #include <conio.h>
 3 
 4 #define CONTENT_SIZE 1048576
 5 using namespace std;
 6 
 7 void proc();
 8 
 9 char src[CONTENT_SIZE];
10 char dst[CONTENT_SIZE];
11 int index = 0;
12 
13 int main() {
14     int n;
15     while ( 1 ) {
16         if ( _kbhit() ) {
17             n = _getch();
18             if ( n == 27 ) //Esc
19                 break;
20             if ( n == 13 ) { //Enter
21                 proc();
22                 continue;
23             }
24             cout << ( char ) n;
25             src[index++] = n;
26         }
27     }
28     return 0;
29 }
30 
31 void proc() {
32     src[index] = '\0';
33     dst[index] = '\0';
34     for ( int i = 0; i < index; i++ )
35         dst[index - i - 1] = src[i];
36     cout << endl << dst << endl << endl;
37     index = 0;
38 }

附件1

posted @ 2019-05-12 12:19  RMS365  阅读(111)  评论(1编辑  收藏  举报