When scanf is used, it will contain spaces or newlines.
How can I delete them?
You can add spaces.
refer to:lautturi.comscanf(" %c", &ch);
It will tell scanf to skip all preceding whitespace (including new-line char).
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[]) {
char ch1;
scanf("%c",&ch1);
printf("%c",ch1);
return 0;
}
example of output:
k 《--Output space
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[]) {
char ch1;
scanf(" %c",&ch1);
printf("%c",ch1);
return 0;
}
example of output:
k k 《--output k