aaaaaa123456789 icon

JV's programming challenge, week 4, testing code 1

aaaaaa123456789 | PRO | 12/05/12 11:20:32 PM UTC | 0 ⭐ | 400 👁️ | Never ⏰ | []
C |

670 B

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include "week4.c"
 
int main (int argc, char ** argv) {
  if (argc < 2) {
    printf("No size specified. Usage: %s <size>\n", *argv);
    return 1;
  }
  unsigned short size;
  if (!sscanf(argv[1], "%hu", &size)) {
    printf("Invalid size specified.\n");
    return 1;
  }
  unsigned short * result = tour(size);
  if (!result)
    printf("No valid tour found.\n");
  else {
    unsigned short * current;
    printf("(%hu, %hu)", *result, result[1]);
    for (current = result + 2; (current - result) < (2 * size * size); current += 2)
      printf(", (%hu, %hu)", *current, current[1]);
    free(result);
    printf(".\n");
  }
  return 0;
}

Comments