Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C language: I cannot find the output file.

  1. Aug 4, 2012 #1
    What is wrong with my code?

    Code (Text):

    #include <stdio.h>

    main(int argc, char *argv[])
        int i=0;
        FILE *fp;
        char fname[100];

        fp=fopen("fname", "w");
        fprintf(fp, "hello world!\n");

    Last edited: Aug 4, 2012
  2. jcsd
  3. Aug 4, 2012 #2

    I like Serena

    User Avatar
    Homework Helper

    Hi nenyan! :smile:

    Can you find a file named "fname" (literally)?
    Last edited: Aug 4, 2012
  4. Aug 4, 2012 #3
    Or, in order to generate the file with the file name that you are expecting, you need to remove the double-quotes from around "fname" in the open statement so that you use the variable name fname and not the literal string "fname"
  5. Aug 4, 2012 #4
    yes....I can....
  6. Aug 4, 2012 #5
    Thank you very much!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook