Untitled
unknown
plain_text
2 months ago
539 B
5
Indexable
#include <stdio.h>
#include <string.h>
#include "leitura.h"
void leitura_string(const char* prompt, char* buffer, int max_len) {
printf("%s", prompt);
if (fgets(buffer, max_len, stdin) != NULL) {
buffer[strcspn(buffer, "\n")] = 0;
}
}
int leitura_inteiro(const char* prompt) {
int valor = 0;
printf("%s", prompt);
if (scanf("%d", &valor) != 1) {
printf("Erro: Entrada inválida.\n");
while (getchar() != '\n');
}
getchar();
return valor;
}Editor is loading...
Leave a Comment