Programing/C- programing
C++ 배열에서 원하는 크기 삭제 프로그램 코드
sosal
2009. 10. 15. 21:16
반응형
/*
* http://sosal.tistory.com/
* made by so_Sal
*/
#include<iostream>
#include<cstring>
using namespace std;
void remove_string(char *s,int start,int n);
int main(void){
char cha[1000];
int a,b; //a:: 시작점 b:: 갯수
cout<<"문자열 입력하세요 : ";
cin.getline(cha,1000); //문자열 입력받습니다.
cout<<"당신이 입력한 문자열입니다"<<endl;
cout<<cha<<endl;
cout<<"삭제하고 싶은 시작점 a와 갯수 b를 입력해주세요 a,b :: ";
cin>>a>>b;
remove_string(cha, a, b);
cout<<"결과입니다."<<endl;
cout<<cha<<endl;
return 0;
}
void remove_string(char *s,int start,int n){
char* pStart=&s[start-1]; // s배열 삭제의 시작점 : pStart
char* pLast =&s[start+n-1]; // s배열 삭제의 끝점 : pLast
strncpy(pStart,pLast,sizeof(pLast)); //pStart 이후로 다 삭제
//널문자 까지 들어가기 때문에
//따로 수정할 필요 없습니다.
}