Skip to content

Instantly share code, notes, and snippets.

@Silva97
Last active Nov 15, 2019
Embed
What would you like to do?
Maneira segura de pegar o input do usuário
/********************
* Developed by Luiz Felipe.
*
* GitHub: https://github.com/Silva97
* Facebook: https://www.facebook.com/B4.0E.B0.48.CD.10.B0.69.CD.10.C3
********************/
#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;
if(text)
fputs(text, stdout);
fgets(buff, sizeof buff, stdin);
va_start(args, format);
ret = vsscanf(buff, format, args);
va_end(args);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment