I'm learning C, and have been trying to make a program that takes user input, and removes any double spaces in it, then prints it out again. We have not done arrays yet so I need to do this char by char. This is my code:
#include <stdio.h>
main()
{
char c;
int count;
count = 0;
while ((c = getchar()) != '\n')
if (c == ' ')
count++;
if (c != ' ')
count = 0;
if (count <= 0)
printf("%s", c);
}
This code does not work, however. The compiler returns the error
:15: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
Any help? I have no clue what I am doing wrong.