title: How to separate string input in two, and use the second one to open/create file, to read and write
body: <p>I am doing a program that reads user input files (coordinates) and it creates a minesweeper mini-game, with bombs placed at given coordinates.
  My problem is with the read option, the input should be: read filename.
  I am trying to separate the string in two, but I'm not doing great.</p>
  <p>ps. I'm a beginner so I probably made stupid mistakes, and the code is a mess right now because it's not finished.</p>
  <pre class="lang-c prettyprint-override"><code>
      #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define map_SIZE 25
  void mapa(void);
  void printUsermap(void);
  void readf(void);
  void bombmaker (void);
  int x, y, i, j;
  int numbers;
  char mines;
  char map[map_SIZE][map_SIZE];
  char final_map[map_SIZE][map_SIZE];
  char umap[map_SIZE][map_SIZE];
  
  void mapa(void){
      int column, row;
  
      
      for(column = 0; column &lt; map_SIZE; column++)
          for(row = 0; row &lt; map_SIZE; row++)
              umap[column][row] = '_';
  }
  
  void printUsermap(){
      int column, row;
  
      system(&quot;cls&quot;);
  
      for(column = 0; column &lt; map_SIZE ; column++)
      {
          for(row = 0; row &lt; map_SIZE; row++)
          {
              printf(&quot;%c&quot;, umap[column][row]);
          }
          printf(&quot;\n&quot;);
      }
      
          
      }
  void bombmaker (){
      int i=0, j=0;
      if( map[i][j] != '*')
              {
                  map[i][j] = '*';
                  final_map[i][j] = map[i][j];
                  mines++;
              }
  }
  
  void readf(){
      
      char string[50] = &quot;practice try.ini &quot;;
         // Extract the first token
         char * token = strtok(string, &quot; &quot;);
         // loop through the string to extract all other tokens
         while( token != NULL ) {
            printf( &quot; %s\n&quot;, token ); //printing each token
            token = strtok(NULL, &quot; &quot;);
         }
  //reading second string
      /*char buff[128];
       int i = 0;
       scanf(&quot;%s&quot;,buff);
                  
        char *p = strtok (buff, &quot; &quot;);
        char *div_var[2];
        while (p)
       {
        div_var[i++] = p;
         p = strtok (NULL, &quot; &quot;);
         }
  
         for (i = 0; i &lt; 2; i++)
        {
          printf(&quot;data[%i] = %s\n&quot;, i+1, div_var[i]);
         }
  
      char ch, file_name[25];
      printf(&quot;&gt; &quot;);
        gets(file_name);
      
         FILE *fp;
          fp = fopen(div_var[1], &quot;r&quot;); // read mode
  
         if (fp == NULL)
         {
            perror(&quot;Error while opening the file.\n&quot;);
            exit(EXIT_FAILURE);
         }
  
         printf(&quot;The contents of %s file are:\n&quot;, file_name);
  
         while((ch = fgetc(fp)) != EOF)
            printf(&quot;%c&quot;, ch); */
  }
      
  int main()
  {
    char option[128];
  
    // MENU
    printf(&quot;+-----------------------------------------------------\n&quot;);
  
    printf(&quot; read &lt;filename&gt;     - read input file\n show                - show the mine map\n trigger &lt;x&gt; &lt;y&gt;     - trigger mine at &lt;x&gt; &lt;y&gt;\n plant &lt;x&gt; &lt;y&gt;       - place armed mine at &lt;x&gt; &lt;y&gt;\n export &lt;filename&gt;   - save file with current map\n quit                - exit program\n sos                 - show menu\n &quot;);
  
    printf(&quot;+-----------------------------------------------------\n&quot;);
      
      
    do{
      printf(&quot;&gt;&quot;);
      scanf (&quot;%s&quot;, option);
  
  
      //Opcao read
        //if (strcmp(option, &quot;plant&quot;)!=0 || strcmp(option,&quot;tigger&quot;)!=0 || strcmp(option, &quot;show&quot;)!=0 || strcmp(option, &quot;export&quot;)!=0 || strcmp(option, &quot;quit&quot;)!=0){
        if (strcmp(option, &quot;read&quot;)==0){
            
            readf();
        }
    
  
  
      // Option show
  
      if (strcmp(option, &quot;show&quot;)==0)
      {
      mapa();
      printUsermap();
      }
  
      // Option trigger
  
  
      else if (strcmp(option, &quot;trigger&quot;)==0)
      {
        scanf(&quot;%d %d&quot;, &amp;x, &amp;y);
        if (x &gt;= 25 || y &gt;= 25){
        fprintf(stdout, &quot;Invalid coordinate\n&quot;);
        }
        else if (map[i][j] == '.'){
        map[i][j] = '*';
        final_map[i][j] = map[i][j];
        mines++;
        }
  
        else{
        fprintf(stdout, &quot;No mine at specified coordinate\n&quot;);
        //fprintf(stdout,&quot;Hello. My name is Inigo Montoya. You killed my father. Prepare to die\n&quot;);
        }
      }
  
      // Option plant
  
       
  
      else if (strcmp(option, &quot;plant&quot;)==0)
      {
        scanf(&quot;%d %d&quot;, &amp;x, &amp;y);
        if (x &gt;= 25 || y &gt;= 25){
        fprintf(stdout, &quot;Invalid coordinate\n&quot;);
        }
        else if (map[i][j] == '_'){
        map[i][j] = '.';
        final_map[i][j] = map[i][j];
        mines++;
        }
  
        else if (map[i][j] == '*'){
        map[i][j] = '.';
        final_map[i][j] = map[i][j];
        mines++;
        }
  
        else{
        //printf (&quot;You're gonna need a bigger boat\n&quot;);
        }
      }
  
      // Opcao export
      else if (strcmp(option, &quot;export&quot;)==0)
      {
          FILE * fp;
          fp = fopen(&quot;file1.text&quot;,&quot;w&quot;);
          fprintf(fp, &quot;teste&quot;);
          fclose(fp);
      }
  
      // Opcao SOS
      else if (strcmp(option, &quot;sos&quot;)==0)
      {
        printf(&quot;+-----------------------------------------------------\n&quot;);
  
        printf(&quot; read &lt;filename&gt;     - read input file\n show                - show the mine map\n trigger &lt;x&gt; &lt;y&gt;     - trigger mine at &lt;x&gt; &lt;y&gt;\n plant &lt;x&gt; &lt;y&gt;       - place armed mine at &lt;x&gt; &lt;y&gt;\n export &lt;filename&gt;   - save file with current map\n quit                - exit program\n sos                 - show menu\n &quot;);
  
        printf(&quot;+-----------------------------------------------------\n&quot;);
          
      
      }
    }
  
    while (strcmp(option,&quot;quit&quot;)!=0);
  
      return 0;
  }
  
  </code></pre>