title: How do I create a global string variable, set it somewhere, and fputs it to a file?
body: <p>I'm new to the C language although I hear its very similar to c++ since c++ is kind of an add on to C?</p>
  
  <p>I can't seem to get a global variable (empty string) to be set in a method and then printed to a text file.</p>
  
  <p>I've tried a few things, but based on what seems to make sense and worked for me in other parts of my program.. this is where I'm at:</p>
  
  <pre><code>char fileReqName[1024] = "";//trying to create the global variable
  //code lines and methods
  //theres a pointer that point's to a "token" thats a string.. called pptr
  strncpy(fileReqName, pptr, sizeof(pptr));
  
  //in another method:
  fputs(fileReqName,file_ptr);
  </code></pre>
  
  <p>But it's not working.</p>
  
  <p>It's supposed to be getting a "filename" from a browser request. Sometimes it's cutting the name of the file the browser goes to into a smaller string and sometimes its not displaying anything. It could be a problem with the token, but when I was displaying it before, the token was always correct.</p>
  
  <p>I also just tried:</p>
  
  <pre><code>strcpy(fileReqName, pptr);
  </code></pre>
  
  <p>which seems to work sometimes as well haha. I think I might have to check the other code for why it's not displaying the correct string/path?</p>
  
  <p>Any suggestions? Thanks</p>