Skip to content

Instantly share code, notes, and snippets.

Last active Nov 15, 2019
What would you like to do?
Maneira segura de pegar o input do usuário
* Developed by Luiz Felipe.
* GitHub:
* Facebook:
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
int lscanf(char *text, const char *format, ...);
int main(){
char str[6];
int x, y, z;
lscanf("Valor de STR: ", "%5s", str);
lscanf("Valor de X: ", "%d", &x);
lscanf("Valor de Y: ", "%d", &y);
lscanf("Valor de Z: ", "%d", &z);
printf("str = %s\n", str);
printf("x = %d\n", x);
printf("y = %d\n", y);
printf("z = %d\n", z);
return 0;
int lscanf(char *text, const char *format, ...){
char buff[MAX_INPUT];
int ret;
va_list args;
fputs(text, stdout);
fgets(buff, sizeof buff, stdin);
va_start(args, format);
ret = vsscanf(buff, format, args);
return ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment