Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't believe the compiler will allow you to declare a variable at that point in the function, of course that is dependent on compiler/settings/etc. Maybe try beginning and ending <code>{}</code>:</p> <pre><code>{ /*the other variables are declared and defined before this code fragment*/ FILE *pfile; pfile=fopen("textfile.txt","w"); fprintf(pfile, "%d", number-&gt;var_inp); fclose(pfile); } </code></pre> <p>to address any scoping issues you may be running into.</p> <p>To address some of your questions:</p> <pre><code>`The program '[5780] lencod.exe' has exited with code 300 (0x12c).` </code></pre> <p>This looks fine, as far as being able to compile the code with no errors. Likely the file is being written to, but you would have to open it up and look to make sure. The text file will be in the working directory, where the program is executing. Placing an absolute path, may be a bit more convenient, such as</p> <pre><code> pfile=fopen("C:\\textfile.txt","a"); </code></pre> <p>You may want to just append for debugging purposes for now. Also, you may want to include a test message like:</p> <pre><code> fprintf(pfile, "Get the number\n"); fprintf(pfile, "%d", number-&gt;var_inp); </code></pre> <blockquote> <p>I have a question: IF you're going to use FILE as a data type, do you have to declare it anywhere else in the program other than putting <code>#include &lt;stdio.h&gt;</code>?????????</p> </blockquote> <p>If you are going to use the <code>stdio.h</code> definition of <code>FILE</code>, it must <strong>not</strong> be declared anywhere else. In short, do not declare any type as <code>FILE</code>, use the <code>stdio.h</code> definition.</p> <blockquote> <p>What do you mean by scoping issues?</p> </blockquote> <p>It appears your compiler, expects all variables in the <strong>block</strong> to be declared first and then functional code. If you want to create another variable for temporary use, like just to get a handle to a file, you must do it in another scope. One very simple way to define a scope is just to add the, <code>{}</code> around any code. After the new scope is created, you may define new variables, and then work on them. However, any new variables will be inaccessible <em>after</em> the <code>}</code>. In our case, this is of no consequence.</p> <p><strong>EDIT</strong></p> <p>I made this explanation far more accurate, by pulling from KeithThompson's comment. I feel like the comments really deserve to be here, he writes:</p> <blockquote> <p>C89/C90 requires a block (a chunk of code surrounded by <code>{</code> and <code>}</code> to consist of zero or more declarations followed by zero or more statements. Declarations don't have to be at the beginning of a function, just at the beginning of a block. C99 relaxed this rule (borrowing from C++), permitting declarations and statements to be mixed within a block. It looks like your compiler is enforcing the C89/C90 rules. Microsoft's C compiler is notorious for this.</p> </blockquote> <p>This is more succinct <em>and</em> accurate explaination.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload