1
#include <stdio.h>
#include <stdio.h>

int main(){
  char karakter1, karakter2, karakter3;

  printf("Input 3 karakter terserah\n");

  printf("Input karakter :\n");
  scanf("%c ", &karakter1);

  printf("Input karakter :\n");
  scanf("%c ", &karakter2);

  printf("input Karakter :\n");
  scanf("%c ", &karakter3);

  printf("\n");
  printf("Karakter yang diinputkan adalah %c \n", karakter3);
  printf("Karakter yang diinputkan adalah %c \n", karakter2);
  printf("Karakter yang diinputkan adalah %c \n", karakter1);

  printf("\n");
  return 0;
}

When I run the code above, the terminal ask twice input ( in ubuntu, windows is running normally). i read this answer, and still no changes although there isn't white space

this my result

  • 1
    your code is asking 3 times for input. Please be more clear about what is expected and what the code does. You can include input, expected and actual output in the question directly – 463035818_is_not_an_ai Nov 16 '20 at 09:53
  • 5
    and please only tag the language you are actually using. Even if your code can compile as C or as C++, I doubt that you do compile it as both – 463035818_is_not_an_ai Nov 16 '20 at 09:53
  • 1
    Because `scanf` must know when the white-space ends, you must give some non-space extra input. Always use *leading* space instead. – Some programmer dude Nov 16 '20 at 09:55
  • 1
    And **always** check the return value from `scanf()` so you know if it worked or not. `scanf()` is not a good way to get input - it's too easy for input to cause it to fail. – Andrew Henle Nov 16 '20 at 10:05

1 Answers1

1

This should work fine for you now.

  #include <stdio.h>
  #include <stdio.h>

  int main(){
  char karakter1, karakter2, karakter3;

  printf("Input 3 karakter terserah\n");

  printf("Input karakter :\n");
  scanf(" %c", &karakter1);

  printf("Input karakter :\n");
  scanf(" %c", &karakter2);

  printf("input Karakter :\n");
  scanf(" %c", &karakter3);

  printf("\n");
  printf("Karakter yang diinputkan adalah %c \n", karakter3);
  printf("Karakter yang diinputkan adalah %c \n", karakter2);
  printf("Karakter yang diinputkan adalah %c \n", karakter1);

  printf("\n");
  return 0;
}