C Program to Remove Spaces from a String
Login/Signup to comment
4 comments on “C Program to Remove Spaces from a String”
×
30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
Login/Signup to comment
Get Hiring Updates right in your inbox from PrepInsta
#include
#include
int removespaces(char *str)
{
int traverse;
for(traverse = 0; str[traverse]; traverse += 1)
{
if(str[traverse] == ‘ ‘)
{
continue;
}
printf(“%c”,str[traverse]);
}
}
void main()
{
char str[100];
scanf(“%[^\n]”,str);
removespaces(str);
}
#python code
n=input()
a=[]
for i in n:
if i!=’ ‘:
a.append(i)
print(*a,sep=””)
#include
#include
main()
{
int i;
int j;
char str[100];
printf(“enter a string with space”);
gets(str);
for(i=0;str[i]!=’\0′;i++)
{
if(str[i]==’ ‘)
{
for(j=i;str[j]!=’\0’;j++)
{
str[j]=str[j+1];
}
}
}
puts(str);
}
#include
#include
void main()
{
int i, j;
char str[100];
printf(“enter the string you want:”);
gets(str);
for (i = 0; str[i] != 0; i++)
{
while (str[i] == ‘ ‘ )
{
for (j = i; str[j] != 0; j++)
{
str[j] = str[j + 1];
}
str[j] = ‘\0’;
}
}
printf(“the string is new one is %s”, str);
}