Hello everyone, this is my first post here.
This program is supposed to, if more than one space is found, only print one and then continue printing the line and do the same for any other spaces that are more than one.
When I run it, it shortens the trail of spaces but I think it only removes one.
What's up with this?
This program is supposed to, if more than one space is found, only print one and then continue printing the line and do the same for any other spaces that are more than one.
C:
#include <stdio.h>
int getandshort(char store[], char hold[]);
int nullit(char arr[]);
int main()
{
int i;
char storeline[100];
char holdspace[100];
nullit(storeline);
nullit(holdspace);
getandshort(storeline, holdspace);
for(i = 0; i < 100; ++i)
printf("%c", storeline[i]);
return 0;
}
int getandshort(char store[], char hold[])
{
int i;
int c;
for(i = 0; (c = getchar()) != '\n' && c != EOF; ++i)
{
if(c != ' ' || c == ' ' && store[i - 1] != ' ')
store[i] = c;
}
store[i] = '\0';
}
int nullit(char arr[])
{
int i;
for(i = 0; i < 100; ++i)
{
arr[i] = '\0';
}
}
When I run it, it shortens the trail of spaces but I think it only removes one.
What's up with this?