title: fprintf, strings and vectors
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3634766/c-printf-on-strings-prints-gibberish">c++ - printf on strings prints gibberish</a>  </p>
  </blockquote>
  
  
  
  <p>I would like to write several strings to file . The strings are </p>
  
  <pre><code>37 1 0 0 0 0
  15 1 0 0 0 0
  33 1 0 0 0 0
  29 1 0 0 0 0
  18 1 0 0 0 0
  25 1 0 0 0 0
  </code></pre>
  
  <p>I first would like to store each line as elements of a string array, then call the same string array and write its element to file.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int writeFile() {
  
    char line[100];
    char* fname_r = "someFile_r.txt"
    char* fname_w = "someFile_w.txt"; 
    vector&lt;string&gt; vec;
  
    FILE fp_r = fopen(fname_r, "r");
    if(fgets(line, 256,fp_r) != NULL)   {
       vec.push_back(line);
    }
  
    FILE fp_w = fopen(fname_w, "w");
    for(int j = 0; j&lt; vec.size(); j++) {
      fprintf(fp_w, "%s", vec[j]); // What did I miss? I get funny symbols here. I am expecting an ASCII
    }
  
    fclose(fp_w);
    fclose(fp_r);
    return 0;
  }
  </code></pre>