<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — [new user] Compile/build a pure C code (How to?/Examples?)]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=756&amp;type=atom" />
	<updated>2020-06-12T16:01:35Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=756</id>
		<entry>
			<title type="html"><![CDATA[Re: [new user] Compile/build a pure C code (How to?/Examples?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=3507#p3507" />
			<content type="html"><![CDATA[<p>Thank you, Jeff !</p>]]></content>
			<author>
				<name><![CDATA[petran]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3921</uri>
			</author>
			<updated>2020-06-12T16:01:35Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=3507#p3507</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [new user] Compile/build a pure C code (How to?/Examples?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=3506#p3506" />
			<content type="html"><![CDATA[<p>I&#039;m not sure why it wasn&#039;t appearing.&nbsp; My guess is that there is an issue flushing the standard output prior to awaiting input.&nbsp; It is considered a bug with Simply Fortran, and I&#039;ll look at it today.</p><p>You&#039;re still receiving an error because <em>main</em> functions are normally defined as:</p><div class="codebox"><pre><code>int main(int argc, char *argv[])</code></pre></div><p>and normally end with</p><div class="codebox"><pre><code>return 0; /* Or any exit code */</code></pre></div><p>The use of <em>exit(0)</em> in you code is a little surprising, especially if it&#039;s from a book.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2020-06-12T14:14:41Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=3506#p3506</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [new user] Compile/build a pure C code (How to?/Examples?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=3505#p3505" />
			<content type="html"><![CDATA[<p>Hello Jeff,</p><p>Thank you very much for your time and for the quick reply! I copied the example from a book and did not expect to have these bugs. Do you have an idea, why it isn&#039;t appearing in the Simply Fortran Console tab on Windows ? I received a compilation warning:<br />&nbsp; &nbsp; return type defaults to &#039;int&#039; [-Wimplicit-int]</p><p>Thank you in advance,<br />Peter</p>]]></content>
			<author>
				<name><![CDATA[petran]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3921</uri>
			</author>
			<updated>2020-06-12T14:07:51Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=3505#p3505</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [new user] Compile/build a pure C code (How to?/Examples?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=3503#p3503" />
			<content type="html"><![CDATA[<p>Peter,</p><p>Your code has a handful of problems that are not allowing it to compile.&nbsp; First, if you&#039;re going to call <em>printf</em> and <em>scanf</em>, you need to also include <strong>stdio.h</strong>.&nbsp; Second, if you&#039;re going to call <em>exit</em>, you need to include <strong>stdlib.h</strong>.&nbsp; Third, there is a syntax error on line 29 that the compiler correctly flags:</p><div class="codebox"><pre><code>.\alone.c:29:25: error: expected &#039;;&#039; before &#039;)&#039; token
   29 |    xl = (-b-sqrt(D))/2*a);
      |                         ^</code></pre></div><p>If you look at line 30, it probably should look more like that.</p><p>With those changes, the code does run, though it isn&#039;t appearing in the Simply Fortran Console tab on Windows.&nbsp; It works fine by running in an external console, though.&nbsp; The modified code is:</p><div class="codebox"><pre><code>/* Program quad_root.c */

#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

main(){
   float a, b, c;
   float xl, x2;
   float D;

   printf(&quot;Enter coefficient a:&quot;);
   scanf(&quot;%f&quot;,&amp;a);
   /* test for quadratic */
   if (a==0){
     printf(&quot;Illegal quadratic!\n&quot;);
     exit(0) ;
   }
   printf(&quot;Enter coefficient b:&quot;);
   scanf(&quot;%f&quot;,&amp;b);
   printf(&quot;Enter coefficient c: &quot; ) ;
   scanf(&quot;%f&quot;,&amp;c);
   /* Compute argument for square root and
      test for complex roots */
   D = b*b - (4*a*c);
   if(D &lt; 0){
     printf(&quot;complex roots! \n&quot;);
     exit(0);
   }
   /* Compute roots of quadratic*/
   xl = (-b-sqrt(D))/(2*a);
   x2 = (-b+sqrt(D))/(2*a);
   /* Output the results*/
   printf(&quot;xl = %f\n&quot;,xl);
   printf(&quot;x2 = %f\n&quot;,x2);
   exit(0);
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2020-06-12T11:28:30Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=3503#p3503</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[[new user] Compile/build a pure C code (How to?/Examples?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=3502#p3502" />
			<content type="html"><![CDATA[<p>Hello,</p><p>I am a new user of SF.</p><p>I could successfully compile Fortran code. I would like now to compile a pure C code. I tried it with a simple code (see below) but it didn&#039;t work. Could you please give me a feedback, why this simple code doesn&#039;t work?</p><p>Thank you in advance,<br />Peter</p><p>/* Program quad_root.c */</p><p>#include &lt;math.h&gt;</p><p>main(){<br />&nbsp; &nbsp;float a, b, c;<br />&nbsp; &nbsp;float xl, x2;<br />&nbsp; &nbsp;float D;</p><p>&nbsp; &nbsp;printf(&quot;Enter coefficient a:&quot;);<br />&nbsp; &nbsp;scanf(&quot;%f&quot;,&amp;a);<br />&nbsp; &nbsp;/* test for quadratic */<br />&nbsp; &nbsp;if (a==0){<br />&nbsp; &nbsp; &nbsp;printf(&quot;Illegal quadratic!\n&quot;);<br />&nbsp; &nbsp; &nbsp;exit(0) ;<br />&nbsp; &nbsp;}<br />&nbsp; &nbsp;printf(&quot;Enter coefficient b:&quot;);<br />&nbsp; &nbsp;scanf(&quot;%f&quot;,&amp;b);<br />&nbsp; &nbsp;printf(&quot;Enter coefficient c: &quot; ) ;<br />&nbsp; &nbsp;scanf(&quot;%f&quot;,&amp;c);<br />&nbsp; &nbsp;/* Compute argument for square root and<br />&nbsp; &nbsp; &nbsp; test for complex roots */<br />&nbsp; &nbsp;D = b*b - (4*a*c);<br />&nbsp; &nbsp;if(D &lt; 0){<br />&nbsp; &nbsp; &nbsp;printf(&quot;complex roots! \n&quot;);<br />&nbsp; &nbsp; &nbsp;exit(0);<br />&nbsp; &nbsp;}<br />&nbsp; &nbsp;/* Compute roots of quadratic*/<br />&nbsp; &nbsp;xl = (-b-sqrt(D))/2*a);<br />&nbsp; &nbsp;x2 = (-b+sqrt(D))/(2*a);<br />&nbsp; &nbsp;/* Output the results*/<br />&nbsp; &nbsp;printf(&quot;xl = %f\n&quot;,xl);<br />&nbsp; &nbsp;printf(&quot;x2 = %f\n&quot;,x2);<br />&nbsp; &nbsp;exit(0);<br />}</p>]]></content>
			<author>
				<name><![CDATA[petran]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3921</uri>
			</author>
			<updated>2020-06-12T09:10:53Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=3502#p3502</id>
		</entry>
</feed>
