Answers for "how to remove spaces from string in c"

C
0

how to get rid of all spaces in a string in c

#include<stdio.h>

char *remove_white_spaces(char *str)
{
    int i = 0, j = 0;
    while (str[i])
    {
        if (str[i] != ‘ ‘)
            str[j++] = str[i];
        i++;
    }
    str[j] = ‘’;
    return str;
}

int main()
{
    char str[50];
    printf("nt Enter a string : ");
    gets(str);
    remove_white_spaces(str);
    printf(“%s”,str);
    return 0;
}
Posted by: Guest on June-24-2020
0

how to remove white spaces in a string in c programming

char *remove_white_spaces(char *str)
{
	int i = 0, j = 0;
	while (str[i])
	{
		if (str[i] != ‘ ‘)
          str[j++] = str[i];
		i++;
	}
	str[j] = ‘’;
	return str;
}

int main()
{
	char str[50];
  printf("nt Enter a string : ");
	gets(str);
	remove_white_spaces(str);
	printf(“%s”,str);
	return 0;
}
Posted by: Guest on August-21-2021

Code answers related to "how to remove spaces from string in c"

Code answers related to "C"

Browse Popular Code Answers by Language