Skip to content

Instantly share code, notes, and snippets.

@int0x33
Created February 17, 2019 12:06
Show Gist options
  • Save int0x33/bd9e38b230e7da56032d7d611c19bceb to your computer and use it in GitHub Desktop.
Save int0x33/bd9e38b230e7da56032d7d611c19bceb to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 8
int main () {
char* username, *nlptr;
int allow = 0;
username = malloc(LENGTH * sizeof(*username));
if (!username)
return EXIT_FAILURE;
printf external link("Enter your username, please: ");
fgets(username,LENGTH, stdin);
// fgets stops after LENGTH-1 characters or at a newline character, which ever comes first.
// but it considers \n a valid character, so you might want to remove it:
nlptr = strchr(username, '\n');
if (nlptr) *nlptr = '\0';
if (grantAccess(username)) {
allow = 1;
}
if (allow != 0) {
priviledgedAction();
}
free(username);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment