감 ¶
드 ¶
ver.1 ¶
문만 되는 로그램
~cpp /* 력 문 반대로 력는 로그램*/ #include <stdio.h> #include <string.h> #include <stdlib.h> char strchange(char ch[50], int lenstr); void main() { char ch[50], *pCh; int lenstr; FILE *fp1, *fp2; pCh = ch; fp1 = fopen("source.txt", "r"); fgets(ch, 50, fp1); // fclose(fp1); printf("Before string = %s \n", ch); lenstr = strlen(ch); *pCh = strchange(pCh, lenstr); fp2 = fopen("result.txt", "w"); printf("After string = %s \n", ch); fputs(ch, fp2); fclose(fp2); } char strchange(char *pCh, int lenstr) { int i; char temp[50]; for(i = 0; i <= lenstr; i++) { temp[i] = *(pCh+i); } for(i = 0; i <=lenstr; i++) { *(pCh+lenstr-i-1) = temp[i]; } return *pCh; }
ver.2 ¶
~cpp /* 력 문 반대로 력는 로그램 ver.2*/ #include <stdio.h> #include <string.h> #include <stdlib.h> char strchange(char ch[50], int lenstr, int choiceNum); void main() { char ch[50], *pCh; int lenstr, choiceNum, i = 0; FILE *fp1, *fp2; pCh = ch; fp1 = fopen("source.txt", "r"); fp2 = fopen("result.txt", "w"); fgets(ch, 50, fp1); // lenstr = strlen(ch); if('A'<= ch[i] && ch[i] <='z') { choiceNum = 0; // }else { choiceNum = 1; // 글?? } *pCh = strchange(pCh, lenstr, choiceNum); fputs(ch, fp2); fclose(fp1); fclose(fp2); } char strchange(char *pCh, int lenstr, int choiceNum) { int i; char temp[50]; switch(choiceNum) { case 0: for(i = 0; i <= lenstr; i++) { *(temp+i) = *(pCh+i); } for(i = 0; i <= lenstr; i++) { *(pCh+lenstr-i-1) = *(temp+i); } break; case 1: for(i = 0; i < lenstr; i++) { *(temp+i) = *(pCh+i); } for(i = 0; i < lenstr; i+=2) { *(pCh+lenstr-i-2) = *(temp + i); *(pCh+lenstr-i-1) = *(temp+i+1); } break; } return *pCh; }
C++ 로 ¶
~cpp //cpp1.cpp #include <iostream.h> #include <string.h> #include "cpp.h" void main() { Mystring mystr; mystr.input(); mystr.str_reverse(); mystr.output(); }
~cpp //cpp2.cpp #include <iostream.h> #include "cpp.h" #include <string.h> void Mystring::str_reverse() { str_len = strlen(ch); int i = 0; while(ch[i])// 단 만 된다. { str_temp[str_len-i-1] = ch[i]; ++i; } } void Mystring::input() { cin>>ch; } void Mystring::output() { int i = 0; while(str_temp[i] > 0) { cout<<str_temp[i]; ++i; } cout<<"\n"; }
~cpp //cpp.h class Mystring { private : char ch[50]; int str_len; char str_temp[50]; public : void str_reverse(); void input(); void output(); };
나 말 ¶
글로된 문 력 때 다른 결과가 나다. 를들 경 란 문를 력면 置 렇게 나 .... 내가 만든 렇게 나다 가 ..ㅠ.ㅠ --경
발견다. 글 글는 벳(1바)과 달리 2바다. 따라 드 같 면 같 벳 꾸로 력되만 글 문 바뀌게 됩다. 글같 2바 문 반대로 력되게 구 보. - 보
베는 글나 본럼 2바를 는 글 경 -_- 단고 글 단로 는 가 긴 데 는 벳과 같 1바 문 면 2바 문를 떻게 구 까? - zyint
ascii code를 봐 MSB ( most significant bit)가 1 면 .. 2바문 겁다.. -
글로 봤는데, 로그램 만 되나, 고 각다. MSB를 면 되겠군. MSB 대 명 다. --
MSB는 로 된 값 가 되는 값 말다. 가령 10001000 라는 값 때 가 는 1 MSB다. 가로 가 는 0 LSB (Least Significant Bit)라고 다. 명드린 내 BigEndian Machine 경, , 를 른로 는 MSB, LSB를 명드린 것고, LittleEndian (를 른 로 는) 는 LSB MSB가 바뀌겠. 대 모든 문 ascii 드로 다. ascii드 값 0~127데 를 8 2 보를 면 MSB가 모두 0 됩다. 경는 당 문가 1바 문란 것 뜻고, MSB가 1 경는 뒤 부가 보가 더 다 (, 문는 2바 문다)라는 것 말다.
렵다 ㅠ