experimenting with GETCH and dividing sections a bit when actually ran
This commit is contained in:
parent
26ced52008
commit
b8ab6baa8b
1 changed files with 43 additions and 4 deletions
45
main.c
45
main.c
|
|
@ -2,7 +2,25 @@
|
|||
|
||||
//importing basic modules
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
#include <conio.h>
|
||||
#define GETCH() _getch()
|
||||
#else
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
char getch() { // Fucking painful why is this piece of shit needed on UNIX Based/Unix-like systems
|
||||
struct termios oldt, newt;
|
||||
tcgetattr(STDIN_FILENO, &oldt); // save old settings
|
||||
newt = oldt;
|
||||
newt.c_lflag &= ~(ICANON | ECHO); // disable buffering and echo
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt); // apply new settings
|
||||
char ch67 = getchar(); // read one char instantly
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // restore old settings
|
||||
return ch67;
|
||||
}
|
||||
#define GETCH() getch()
|
||||
#endif
|
||||
|
||||
// STRUCTURE TEST
|
||||
struct man {
|
||||
|
|
@ -123,6 +141,15 @@ int main() {
|
|||
LOIS.weight = 60;
|
||||
printf("Our woman is unknown, she is not %d years old and she weights %dkg. (LOIS.age and LOIS.weight).", LOIS.age, LOIS.weight);
|
||||
|
||||
// PRESS ANY KEY TO CONTINUE
|
||||
printf("\n\nPress any key to continue...");
|
||||
GETCH();
|
||||
#ifdef _WIN32
|
||||
system("cls");
|
||||
#else
|
||||
system("clear");
|
||||
#endif
|
||||
|
||||
// INPUT (BUT ONLY FOR ONE WORD! STOPS WHEN YOU PUT IN A SPACE)
|
||||
printf("\n\nINPUT BELOW:\n"); // DIVIDER
|
||||
char fruit[50]; //MAX 50 CHARACTERS
|
||||
|
|
@ -140,7 +167,19 @@ int main() {
|
|||
scanf(" %49[^\n]", vegetable); // the "[^\n]" means to read everything except a newline, which means you can input spaces inside now, 49 makes it so it doesnt crash once it has more than 50 characters
|
||||
printf("The %s will be a perfect choice for this salat!", vegetable);
|
||||
|
||||
// END
|
||||
// END OF THE MAIN.C CODE, HERE YOU WILL BE ABLE TO CONTINUE ON TO OTHER EXPERIMENTS OF MINE
|
||||
printf("\n\nSWITCH OVER TO\n"); // DIVIDER
|
||||
printf("1 = DvorakMSDOS.C, 2 = exit\n");
|
||||
while (getchar() != '\n') {} // same use case as above in the first input part of the code
|
||||
while (1==1) {
|
||||
fflush(stdout); // same use case as above in the first input part of the code
|
||||
char chc = GETCH();
|
||||
if (chc == '1') {
|
||||
printf("placeholder");
|
||||
} else if (chc == '2') {
|
||||
return 0;
|
||||
// THIS IS THE CURRENT END OF MY LESSON
|
||||
} else {
|
||||
printf("invalid character, try again!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue