Last active
January 7, 2020 21:57
-
-
Save jucie/389cc88c0378f8ac4712d361abd27e44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void funcao_correta(FILE *out, int idade) { | |
fprintf(out,"a pessoa tem %d anos", idade); | |
} | |
void funcao_incorreta(FILE *out, int idade) { | |
fprintf(out,"a pessoa tem %d anos", idade*2); | |
} | |
int main(int argc, const char *argv) { | |
const char O_CERTO[] = "a pessoa tem 3 anos"; | |
char buffer[32]; | |
FILE *f; | |
f = fopen("NUL","wt"); /* para unix troque o nome de arquivo por /dev/null */ | |
if ( !f ) { | |
fputs("Falhou abrindo arquivo", stderr); | |
return 1; | |
} | |
setvbuf(f, buffer, _IOFBF, sizeof buffer); | |
funcao_correta(f, 3); | |
if (memcmp(buffer, O_CERTO, strlen(O_CERTO)) != 0) { | |
fputs("funcao_correta() nao produziu o resultado correto\n", stderr); | |
} | |
setvbuf(f, buffer, _IOFBF, sizeof buffer); | |
funcao_incorreta(f, 3); | |
if (memcmp(buffer, O_CERTO, strlen(O_CERTO)) != 0) { | |
fputs("funcao_incorreta() nao produziu o resultado correto\n", stderr); | |
} | |
fclose(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment