Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %zu\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %zu\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %zu\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {
edited body
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %ld\n"%zu\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %ld\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %zu\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {
added 571 characters in body
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %ld\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.

The thing that feels unusual is the use of freopen to send the test data to stdin.

Are there better ways to implement this kind of test?

C has a freopen() footnote

The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned by the fopen function may be assigned.

This looks like a good direct way to test code, although I'd expect stdout, strderr being re-opened to capture output.


Are there better ways

Enable all compiler warnings - save time.

The mismatch of specifier and type implies code is not efficiently using the 1st round of code improvement: Compiler warnings.

// printf("ok: tmpnum == %ld\n", tmpnum);
printf("ok: tmpnum == %ld\n", tmpnum);

Code is strange in that it passes in tmpnum for no good reason.

//static size_t get_num(size_t tmpnum) {
// if (scanf("%zu", &tmpnum) != 1) {
static size_t get_num(void) {
 size_t tmpnum;
 if (scanf("%zu", &tmpnum) != 1) {
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /