C language remove newline characters in scanf

C language remove newline characters in scanf

When scanf is used, it will contain spaces or newlines.
How can I delete them?

You can add spaces.

r‮‬efer to:lautturi.com
scanf(" %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
Created Time:2017-08-29 10:21:57  Author:lautturi