Skip to content

Instantly share code, notes, and snippets.

@sidewinder040
Created January 2, 2021 19:45
Show Gist options
  • Save sidewinder040/2f12c90b7729f7705fdbe1a4d288e4e8 to your computer and use it in GitHub Desktop.
Save sidewinder040/2f12c90b7729f7705fdbe1a4d288e4e8 to your computer and use it in GitHub Desktop.
A safer way to get user data, limited to size of Buffer
// A safer way to get user data, limited to size of Buffer
#include <stdio.h>
#define BUFFER_SIZE 15
int main(int argc, char const *argv[])
{
printf("Please enter your name: ");
char name[BUFFER_SIZE];
fgets(name, sizeof(name), stdin);
printf("Hello %s", name);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment