hello guys,
i had been working with one program where it eliminates one or more balnk space in a string to single blank space. i have written a program which compiles and run success. and below is my code, can any one tell me how can i improve this program to work better and minimise the code or what i have writtin is more efficient. any comment would be appriciated.
Code:
/* program to replace a string of one or more blanks by a single blank */
#include<stdio.h>
int main()
{
char str[30],temp[20];
int i,count=0,j=0;
printf("Enter the value for the string\n");
fgets(str,sizeof str, stdin);
for(i=0;str[i];i++)
{
if(isspace(str[i]) && count==0)
{
temp[j++]=' ';
count=1;
continue;
}
else if(!isspace(str[i]))
{
count=0;
temp[j++]=str[i];
}
}
temp[j]='\0';
fputs(temp,stdout);
getchar();
return 0;
}
s.s.harish