Hi all, I'm quite new to C programming, so forgive me if I've made silly mistakes. I'm tryin to write a program to remove the extra spaces between words.
For example:
Code:
Input: C Programming is fun.
Output: C Programming is fun.
So far, I'm only able to remove all spaces, and I had a problem with the output of my program. The program would print funny characters at the end of the output. I would greatly appreciate if anyone could point out to me what is wrong, and how I could further implement my code to meet my objectives. (like the above example). Thank you!
Code:
char input[50];
char output[50];
int i=0, j=0;
printf("Input = ");
fgets(input, 50, stdin);
while(input[i]!='\0')
{
if(isspace(input[i]))
i++;
else if(!isspace(input[i]) && input[i]!='\0')
{
output[j] = input[i];
i++;
j++;
}
}
puts(output);
When I run my program, I get
Code:
Input = there is a
Output = thereisa(funny characters here)