Advertisement
krot

Удаление комментариев из строки

Jan 28th, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. char * deltext(char *sim, int nc, int endc){
  2.  int i;
  3.  int dl=endc-nc;
  4.  
  5.  for(i=nc;sim[i]!=0;++i){
  6.         sim[i]=sim[i+dl];
  7.         }
  8.         return sim;  
  9. }
  10.  
  11.  
  12. int main(int narg, char **arg){
  13.  
  14.  
  15.  
  16.  
  17. char sim[]="123 /*text*/ 123 /*text*/ qwe jjj";
  18. int i,nc=-1,endc;
  19. for(i=0;sim[i]!=0;++i){
  20.    if((sim[i]=='/')&&(sim[i+1]=='*')){
  21.         nc=i;//íà÷àëî
  22.     }else if((nc!=-1)&&(sim[i]=='*')&&(sim[i+1]=='/')){
  23.         endc=i;
  24.        *sim=* deltext(sim,nc-1,endc+2);
  25.         }
  26. }
  27.  
  28. cout << sim;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement