Answer the question
In order to leave comments, you need to log in
Where do gaps come from?
The program must remove spaces at the beginning and at the end of the string. In a function, it does its job, but when it returns to main, it breaks.
#include <stdio.h>
#include <stdlib.h>
int size(const char str[])
{
int i = 0;
while(str[i] != '\0')
{
i++;
}
return i;
}
void mutableStrip(char str[])
{
int start = 0;
while(str[start] == ' ')
{
start++;
}
int n = size(str);
int end = 0;
while(str[(n-1) - end] == ' ')
{
end++;
}
str[n-end] = '\0';
str += start;
printf("0%s1 \n", str);
}
int main()
{
char str[] = " ads fh ";
mutableStrip(str);
printf("0%s1 \n", str);
return 0;
}
0ads fh1
0 ads fh1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question