不能运行我的代码,我不知道为什么它不工作

I thought it was the compiler's problem. At first, I used dev c++, and it crashes. Then, I used code blocks, but it shows nothing on the terminal. I am wondering whether it is Windows 10 problem.

#include <stdio.h>
#include <string.h>

#define NUM_PLANETS 9

int main(int argc, char *argv[]) {
  char *planets[] = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn",
      "Uranus", "Neptune", "Pluto"};
  int i, j;
  for (i = 1; i < argc; i++) {
    for (j = 0; j < NUM_PLANETS; j++) {
      if (strcmp(argv[i], planets[j]) == 0) {
        printf("%s is planet %d\n", argv[i], j + 1);
        break;
      }
      if (j == NUM_PLANETS)
        printf("%s is not a planet.\n", argv[i]);
    }
  }
  return 0;
}

转载于:https://stackoverflow.com/questions/53037810/cant-run-my-code-and-i-dont-know-why-it-doesnt-work

the following proposed code:

  1. checks for missing command line parameter
  2. properly exits the program when there is no command line parameter
  3. follows the axion: only one statement per line and (at most) one variable declaration per statement.

and now the proposed code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUM_PLANETS 9

int main(int argc, char *argv[]) 
{
  char *planets[] = 
  {
      "Mercury", 
      "Venus", 
      "Earth", 
      "Mars", 
      "Jupiter", 
      "Saturn",
      "Uranus", 
      "Neptune", 
      "Pluto"
  };

  int i;
  int j;

  if (argc < 2 )
  {
      printf( "USAGE: %s <planet name> ...\n", argv[0] );
      exit( EXIT_FAILURE );
  }

  for (i = 1; i < argc; i++) 
  {
    for (j = 0; j < NUM_PLANETS; j++) 
    {
      if (strcmp(argv[i], planets[j]) == 0) 
      {
        printf("%s is planet %d\n", argv[i], j + 1);
        break;
      }
    }

    if (j == NUM_PLANETS)
        printf("%s is not a planet.\n", argv[i]);
  }

  return 0;
}