//final
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <ctype.h>

int b=0, quantity=0;
char *text[100];



void GETLINE (int x){
char *str;
char *p, c;
int i=0;
str=(char*)malloc(sizeof(char));
str[0]='\0';
do{
str=(char*)realloc(str, sizeof(char)*(i+2));
str[i]=getchar();
i++;
str[i]='\0';
}while (str[i-1]!='\n');
b=(str[0]!='\n');
text[x]=(char*)malloc(sizeof(char)*(strlen(str)+1));
strcpy(text[x],str);
}


void OBSERVE (){
int i, n=0;
for (; n<quantity; n++){
	i=0;
	while ((i<80) && (text[n][i]!='\0')){
		printf("%c",text[n][i]);
		if (i==79) printf ("\n");
		i++;
	}
}
printf("\n");
}

void PASTE_STRING (){
char k[2];
int N, i;
printf ("Plz enter string number \n");
getchar();
scanf ("%s", &k);
if (k[0]=='\n') N=0; else {
N=atoi(k);
N--;
}
printf("\n");
printf ("Plz enter string: \n");
fpurge(stdin);
GETLINE(quantity);
quantity++;
printf ("Plz press enter to continue \n");
GETLINE(quantity);
  i=0;
  while (quantity-i>N) {
      text[quantity-i]=text[quantity-i-1];
      i++;           }
      text[N]=text[quantity];
}


void INPUT_SYMBOL () {
int N,M;
printf ("Enter string number: ");
scanf ("%d", &N);
printf ("Enter symbol number: ");
scanf ("%d", &M);
printf ("Input symbol: ");
getchar();
scanf ("%c", &text[N-1][M-1]);
printf("\n");
}


void DELETE_COMMENTS_2 (void) {
int n=0, i=0, n1=0;
for(n=0; n<=quantity; n++)   {
  for (i=0; text[n][i]!='\0'; i++) 
   if ((text[n][i]=='/') && (text[n][i+1]=='/'))
    { text[n][i]='\n';
      text[n][i+1]='\0';
      if (text[n][0]=='\n') {
	for (n1=n;n1<quantity;n1++) text[n1]=text[n1+1];
 	n--;
	quantity--;}
      break;}
	//str=(char*)realloc(str, sizeof(char)*(i+2));	  
	//text=realloc (text, sizeof(char) text[quantity-1]);
                             } return; }


void DELETE_COMMENTS_1 (void) {
int i,k,n,n1,i1,r,l,p;
k=0; n=0; n1=0; i1=0; p=1;
while (n<=quantity) {
  i=0;
  while (text[n][i]!='\n') {
 if ((text[n][i]=='/') && (text[n][i+1]=='*') && (p!=0))
   {k=1; n1=n; i1=i; p=0;}
 if ((text[n][i]=='*') && (text[n][i+1]=='/') && (k==1))
   {  k=0; 
      if (n==n1) {
	p=1;	
	l=-1;
	do {l++; text[n][i1+l]=text[n][i+l+2];} while (text[n][i+l+2]!='\0');
                 }
      if (n>=n1+1) {
	p=1;
	l=-1;
	do {l++; text[n1][i1+l]=text[n][i+l+2];} while (text[n][i+l+2]!='\0');
	for (l=1; n>=n1+l; text[n1+l][0]='\n', text[n1+l][1]='\0', l++);
                   }
   }  i++;		   }
n++;		    } return;}



int main (void){
char Z;
int x=0, n=0;
printf ("input text\n");
do{
	GETLINE(x);
	x++;
}while (b);
quantity=x-1;
//GETLINE(3);
printf ("enter O if you want to observe text \n");
printf ("enter P if you want to paste a string on N-th place \n");
printf ("enter I if you want to change symbol on M-th place in N-th string \n");
printf ("enter D if you want to delete all coments in the text \n");
printf ("enter E if you want to exit \n \n");
Z=getchar();
printf("\n");
while (Z!='E') { switch (Z) {
  case 'O': OBSERVE (); break;
  case 'P': PASTE_STRING (); break;
  case 'I': INPUT_SYMBOL (); break;
  case 'D': /*DELETE_COMMENTS_2 ();*/ DELETE_COMMENTS_1 (); break;
    }
  printf("------------------------------------------------------------------------------------\n");
  Z=getchar();
  printf("\n");    }
return 0;
}
