0

im trying for hours to figure out what I'm doing wrong but can't seem to find a solution. I want to use getch() so I don't have to put enter to pass the input to a variable. Somehow i still have to press ENTER Here the code:

#include "open_txt.h"

struct daten {
    char *name[50][100];
    char *adress[50][100];
    char *birthday[50][100];
}data;

int main (){
    
    printf("\n\n\tContacts\n\n");

    printf("Main menu: \n\n");

    printf("1. Add contact\n");
    printf("2. Edit contact\n");
    printf("3. Search contact\n");

    /*char *filename;
    filename = "Adressbuch.txt";
    int c = fopen("Adressbuch.txt", "w");*/


    int ui;
    ui = getchar();


    switch(ui){

        case '1':
            printf("\n\n\tADD CONTACT\n\n");
            break;
        case '2':
            printf("\n\nEDIT CONTACT\n\n");
            break;
        case '3':
            printf("\n\nSEARCH CONTACT\n\n");
            break;
        default:
            printf("That's not an option!\n");
    }
    return 0;
}``` 
  • `getch` is not a standard C function. – n. m. could be an AI Dec 12 '20 at 22:05
  • Please post the [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) with complete code that demonstrates the problem. – Weather Vane Dec 12 '20 at 22:06
  • Sorry, I didn't mean just remove a few lines. The [MRE](https://stackoverflow.com/help/minimal-reproducible-example) should be a small, **complete** example that can be copied, compiled just as it is, and run to repeat the problem you are having - needing to press after `getch()`. – Weather Vane Dec 12 '20 at 23:14
  • Which platform are you working on (Windows vs non-Windows, mainly)? What's in `open_txt.h`? Please reread the bit about 'minimal' in the discussion of MRE. Why does your minimal code require the opening of the address book file? Why does it require the `struct daten` definition? – Jonathan Leffler Dec 13 '20 at 00:42
  • Your design of the structure is dubious. A 2D array containing 5,000 pointers is a weird construct. You should probably be using `struct daten { char name[100]; char adress[100]; char birthday[100]; }data;` and then creating an array of fifty of those structures. What you've got is practically unusable, as well as irrelevant to the MRE. – Jonathan Leffler Dec 13 '20 at 00:45

0 Answers0