this code takes out the spaces in between and i want to shrink this code a bit.
like in function modify. It doesnt work if i take out the if(s[i] == ' ')
I want to make this code work without using that.
Any help??
#include<stdio.h>
#include<stdlib.h>
char* modify(char*);
void main()
{
char* str = malloc(100 * sizeof(char));
char* mstr;
printf("Enter a string: ");
gets(str);
mstr= modify(str);
printf("String after removing spaces: %s \n\n",mstr);
}
char* modify(char *s)
{
int i,j=0;
static char temp[200];
for(i = 0; s[i] != '\0'; i++)
{
if(s[i] == ' ')
{}
else
{
temp[j] = s[i];
j++;
}
}
temp[j] = '\0';
return temp;
}