00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 #include "pic24_all.h" 00030 00042 void reverseString(char *psz_s1, char *psz_s2) { 00043 char *psz_s1end; 00044 if (!(*psz_s1)) { 00045 *psz_s2 = 0; //psz_s1 is empty, return. 00046 return; 00047 } 00048 psz_s1end = psz_s1; 00049 //find end of first string 00050 while (*psz_s1end) psz_s1end++; 00051 psz_s1end--; //backup one to first non-zero byte 00052 //now copy to S2 in reverse order 00053 while (psz_s1end != psz_s1) { 00054 *psz_s2 = *psz_s1end; 00055 psz_s1end--; 00056 psz_s2++; 00057 } 00058 //copy last byte 00059 *psz_s2 = *psz_s1end; 00060 psz_s2++; 00061 //mark end of string 00062 *psz_s2 = 0; 00063 } 00064 00065 00066 #define BUFSIZE 63 00067 char sz_1[BUFSIZE+1]; 00068 char sz_2[BUFSIZE+1]; 00069 int main (void) { 00070 configBasic(HELLO_MSG); 00071 while (1) { 00072 inString(sz_1,BUFSIZE); //get a string from the console 00073 reverseString(sz_1, sz_2); 00074 outString(sz_2); //output the reversed string 00075 outString("\n"); 00076 } 00077 }