Home > front end >  How can I read the scanf without changing the printf positions?
How can I read the scanf without changing the printf positions?

Time:06-18

I am very new into programming and have a problem with the scanf. I have to write a program with a structured output but I really don't know how I can read this scanf without changing the output. It's German language used in the output so I have to explain that I'm writing a calculator with bit operators and got the hint that I should use the getNumber function but I haven't found anything to understand how it works.

The first scanf should read the input which is the first number in the calculator while the second scanf should be nothing more than only some bit operators so I declared them in the main function. Here is my code if it helps:

    #include <stdio.h>
#include "escapesequenzen.h"



void dummy(){

    char Dummy;
    
    do
        scanf("%c", &Dummy);
    while(Dummy != '\n');

}


/*

Block zum Kopieren:

printf(
"\n|----------------------------------------------------------|"
"\n| Bitoperatoren-Rechner                                    |"
"\n|                                                          |"
"\n| Eingabe Zahl 1:                                          |"
"\n| Operator:                                                |"
"\n| Eingabe Zahl 2:                                          |"
"\n|                                                          |"
"\n|----------------------------------------------------------|"
"\n|                                                          |"
"\n|          |  dez.  |  okt.  |  hex.  | Binaerdarstellung  |"
"\n|  Zahl 1  |        |        |        |                    |"
"\n| Operator |        |        |        |                    |"
"\n|  Zahl 2  |        |        |        |                    |"
"\n| -------------------------------------------------------- |"
"\n| Ergebnis |        |        |        |                    |"
"\n|                                                          |"
"\n|----------------------------------------------------------|");

*/


void print1(short Zahl1, short Zahl2, int Eingabe, char Dummy){

printf(
"\n|----------------------------------------------------------|"
"\n| Bitoperatoren-Rechner                                    |"
"\n|                                                          |"
"\n| Eingabe Zahl 1:                                          |"
"\n| Operator:                                                |"
"\n| Eingabe Zahl 2:                                          |"
"\n|                                                          |"
"\n|----------------------------------------------------------|"
"\n|                                                          |"
"\n|          |  dez.  |  okt.  |  hex.  | Binaerdarstellung  |"
"\n|  Zahl 1  |        |        |        |                    |"
"\n| Operator |        |        |        |                    |"
"\n|  Zahl 2  |        |        |        |                    |"
"\n| -------------------------------------------------------- |"
"\n| Ergebnis |        |        |        |                    |"
"\n|                                                          |"
"\n|----------------------------------------------------------|");

}

int main(){

    short Zahl1;
    short Zahl2;
    int Eingabe;
    short Operator;
    char Dummy;

    print1(Zahl1, Zahl2, Eingabe, Operator, Dummy);
    getNumber();

    return 0;

}

Edit: If it helps, here is the "escapesequenzen" heather:

#ifndef escapesequenzen_h
   #define escapesequenzen_h escapesequenzen_h

   #define POSITION(Ze, Sp)     printf("\033[%d;%dH",Ze,Sp)
   #define HOME                 printf("\033[H")
   #define UP(Anz)              printf("\033[           
  • Related