Can this code be optimized:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void delThe(char *);
main()
{
char a[100];
printf("enter the sentence\n");
gets(a);
delThe(a);
printf("your sentence\n%s",a);
return 0;
}
void delThe(char *a)
{
int i=0,j=0,k,blank=0;
int old_length, new_length,max,l;
char str[]={"0X20"};
k=strlen(str);
printf("%d\n",k);
while(a[i]!='\0')
{
if(a[i]==' ')
blank++;
i++;
}
old_length=i-1;
new_length=old_length+(3*blank);
max=new_length;
for(j=old_length;j>=0;j--,new_length--)
{ if(a[j]==' ')
{
for(l=k-1;l>=0;l--)
{
a[new_length]=str[l];
new_length--;
}
new_length=new_length+1;
} else
a[new_length]=a[j];
}
a[max+1]='\0';
}
nice work bro
ReplyDelete