<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Source code | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/category/source-code/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Thu, 30 Dec 2021 17:03:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>Source code | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Using JSON as a datastore in C#</title>
		<link>https://learncgames.com/using-json-as-a-datastore-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-json-as-a-datastore-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 01 Jan 2022 00:00:29 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Techniques]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3002</guid>

					<description><![CDATA[<p>For some not too complex applications, JSON can be a very handy way to store data rather than say using a database. It also has the advantage of storing data of varying sizes. For instance Lists with varying numbers of items. I created a Saveable generic class below that you use as an ancestor class [&#8230;]</p>
The post <a href="https://learncgames.com/using-json-as-a-datastore-in-c/">Using JSON as a datastore in C#</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:71,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/geralt-9301\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5113918&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260128125116\/https:\/\/pixabay.com\/users\/geralt-9301\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:37:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-10 20:35:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-14 10:15:04&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-18 00:35:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-22 08:38:06&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-26 04:32:17&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-02 04:40:31&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 06:20:34&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-08 07:10:02&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-12 08:36:56&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-16 00:37:32&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-20 00:37:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-24 00:39:09&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:41:16&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-01 04:35:20&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-04 12:42:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-07 20:34:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-11 12:23:52&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-14 22:51:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-18 12:09:41&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-21 20:02:11&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 20:02:11&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:72,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5113918&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:37:12&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-10 20:35:53&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-14 10:15:04&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-18 00:35:32&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-22 00:43:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-25 02:25:26&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 14:15:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-04 00:33:37&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-07 21:06:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-12 08:36:56&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-16 00:37:32&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-20 00:37:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-24 00:39:10&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:41:16&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-01 04:35:16&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-04 12:42:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-07 20:34:48&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-11 16:11:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-15 00:34:41&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-18 12:09:41&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-21 20:02:12&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 20:02:12&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_3004" aria-describedby="caption-attachment-3004" style="width: 640px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-full wp-image-3004" src="https://learncgames.com/wp-content/uploads/2022/01/shapes.jpg" alt="Shapes" width="640" height="427" srcset="https://learncgames.com/wp-content/uploads/2022/01/shapes.jpg 640w, https://learncgames.com/wp-content/uploads/2022/01/shapes-300x200.jpg 300w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption id="caption-attachment-3004" class="wp-caption-text">Image by <a href="https://pixabay.com/users/geralt-9301/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5113918">Gerd Altmann</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5113918">Pixabay</a></figcaption></figure>
<p>For some not too complex applications, JSON can be a very handy way to store data rather than say using a database. It also has the advantage of storing data of varying sizes. For instance Lists with varying numbers of items. I created a Saveable generic class below that you use as an ancestor class for that you wish to Save/Load an IList of whatever.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre><code class="language-csharp" data-line="">    public class SaveAble&lt;T&gt;
    {
        private string _error = &quot;&quot;;
        string LastError()
        {
            return _error;
        }
        public IList&lt;T&gt;? Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Log.Error(&quot;Missing file {filePath}&quot;);
                _error = $&quot;Missing file {filePath}&quot;;
                return null;
            }

            var content = File.ReadAllText(filePath);
            if (string.IsNullOrEmpty(content))
            {
                Log.Error(&quot;{filePath} file is empty&quot;);
                _error=$&quot;{filePath} file is empty&quot;;
                return null;
            }

            return JsonSerializer.Deserialize&lt;IList&lt;T&gt;&gt;(content, new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            })!;
        }

        public bool Save(string filename,IList&lt;T&gt; collection)
        {
            var options = new JsonSerializerOptions
            {
                WriteIndented = true,
                PropertyNameCaseInsensitive = true
            };
            try
            {
                var bytes = JsonSerializer.SerializeToUtf8Bytes(collection, options);
                File.WriteAllBytes(filename, bytes);
                return true;
            }catch (Exception ex)
            {
                _error = $&quot;Exception:{ex.Message}&quot;;
                return false;
            }
        }

    }
</code></pre>
<p>Just define your class MyClasses from SaveAble&lt;MyClass&gt;</p>
<p>where MyClass is the class you have a List of. Then you can do</p>
<pre>MyClasses myclasses;</pre>
<pre>myclasses.Save("filename",List&lt;MyClass&gt;) and

List&lt;MyClass&gt; list = myclasses.Load("filename");</pre>
<p>It is fast. On my PC (now six years old), it can load a 99,000 line JSON file in well under a second.</p>The post <a href="https://learncgames.com/using-json-as-a-datastore-in-c/">Using JSON as a datastore in C#</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3002</post-id>	</item>
		<item>
		<title>Another maze generator and solver in C</title>
		<link>https://learncgames.com/another-maze-generator-and-solver-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=another-maze-generator-and-solver-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 24 Mar 2021 00:00:23 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[maze]]></category>
		<category><![CDATA[solver]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2944</guid>

					<description><![CDATA[<p>I liked this one; it compiled perfectly without any changes and ran perfectly. It produces a maze of the specified size with a route. That&#8217;s not bad for a program written over 20 years ago. By developer Joe Wingbermuehle. You can view the source code here. It runs in a terminal, just supply width and [&#8230;]</p>
The post <a href="https://learncgames.com/another-maze-generator-and-solver-in-c/">Another maze generator and solver in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:84,&quot;href&quot;:&quot;https:\/\/raw.githubusercontent.com\/joewing\/maze\/master\/maze.c&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250512213511\/https:\/\/raw.githubusercontent.com\/joewing\/maze\/master\/maze.c&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:47:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 14:28:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 13:54:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 14:42:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-26 01:05:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-01 14:50:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 18:50:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 05:20:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 08:08:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 15:26:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 05:35:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 18:52:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-01 14:25:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 00:44:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 15:04:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 20:30:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 17:47:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 01:46:28&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 01:46:28&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="alignleft size-medium wp-image-2945" src="https://learncgames.com/wp-content/uploads/2021/03/solved-maze-298x300.png" alt="Solved maze" width="298" height="300" srcset="https://learncgames.com/wp-content/uploads/2021/03/solved-maze-298x300.png 298w, https://learncgames.com/wp-content/uploads/2021/03/solved-maze-150x150.png 150w, https://learncgames.com/wp-content/uploads/2021/03/solved-maze.png 596w" sizes="(max-width: 298px) 100vw, 298px" />I liked this one; it compiled perfectly without any changes and ran perfectly. It produces a maze of the specified size with a route. That&#8217;s not bad for a program written over 20 years ago. By developer Joe Wingbermuehle. You can v<a title="Link to Maze generator and solver" href="https://raw.githubusercontent.com/joewing/maze/master/maze.c" target="_blank" rel="nofollow noopener">iew the source code here</a>.</p>
<p>It runs in a terminal, just supply width and height characters like this. I compiled it into a file ex1.</p>
<pre>./ex1 15 15 s</pre>
<p>If you provide the s parameter, it will solve it as the screenshot shows using &lt;&gt; for the solved route. off for just the maze.</p>The post <a href="https://learncgames.com/another-maze-generator-and-solver-in-c/">Another maze generator and solver in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2944</post-id>	</item>
		<item>
		<title>Another Minecraft game in C</title>
		<link>https://learncgames.com/another-minecraft-game-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=another-minecraft-game-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 13 Mar 2021 00:00:21 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Minecraft]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2870</guid>

					<description><![CDATA[<p>If you remember back in November I mentioned a Minecraft server that was written in C.  Well now there&#8217;s another one that has appeared. Just lIke the other one it uses SDL2 and OpenGL and includes full source code.  This one uses clang. It&#8217;s cross-platform for Windows and Mac and there are two different binaries, [&#8230;]</p>
The post <a href="https://learncgames.com/another-minecraft-game-in-c/">Another Minecraft game in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:106,&quot;href&quot;:&quot;https:\/\/github.com\/johnpayne-dev\/MinecraftC&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205013358\/https:\/\/github.com\/johnpayne-dev\/MinecraftC&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:58:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 20:27:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 18:54:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 03:22:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 05:32:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 22:47:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 13:36:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 21:36:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 05:16:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:41:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 10:24:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 00:30:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 06:00:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 19:04:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 17:40:46&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 17:40:46&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="alignleft size-medium wp-image-2871" src="https://learncgames.com/wp-content/uploads/2021/03/minecraft-in-c-300x169.png" alt="Minecraft" width="300" height="169" srcset="https://learncgames.com/wp-content/uploads/2021/03/minecraft-in-c-300x169.png 300w, https://learncgames.com/wp-content/uploads/2021/03/minecraft-in-c-1024x576.png 1024w, https://learncgames.com/wp-content/uploads/2021/03/minecraft-in-c-768x432.png 768w, https://learncgames.com/wp-content/uploads/2021/03/minecraft-in-c-1536x863.png 1536w, https://learncgames.com/wp-content/uploads/2021/03/minecraft-in-c.png 1715w" sizes="(max-width: 300px) 100vw, 300px" />If you remember back in November I mentioned a <a title="Link to blog entry about Minecraft in C" href="https://learncgames.com/a-minecraft-clone-in-c/" target="_blank" rel="nofollow noopener">Minecraft server</a> that was written in C.  Well now t<a title="Link to Minecraft on GitHub" href="https://github.com/johnpayne-dev/MinecraftC" target="_blank" rel="nofollow noopener">here&#8217;s another one</a> that has appeared. Just lIke the other one it uses SDL2 and OpenGL and includes full source code.  This one uses clang.</p>
<p>It&#8217;s cross-platform for Windows and Mac and there are two different binaries, one for creative mode and one for survival mode.</p>
<p>It&#8217;s still a work in progress and needs sound effects and music, saving and loading levels and multiplayer to complete it. If you are learning C and want to see how a game like this is programmed, download the source code from GitHub and start studying it.</p>The post <a href="https://learncgames.com/another-minecraft-game-in-c/">Another Minecraft game in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2870</post-id>	</item>
		<item>
		<title>Portable Life in C</title>
		<link>https://learncgames.com/portable-life-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=portable-life-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 28 Feb 2021 00:00:09 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[portable]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2791</guid>

					<description><![CDATA[<p>I&#8217;ve mentioned Life before, this is the cellular automata as discovered by John Horton Conway. It&#8217;s perhaps less of a game and more of a recreation for anyone fascinated by programming. It&#8217;s hard to add up how many man-hours have been spent on it. Developer Justine Tunney (aka Jart on Github) has developed a portable [&#8230;]</p>
The post <a href="https://learncgames.com/portable-life-in-c/">Portable Life in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:140,&quot;href&quot;:&quot;https:\/\/justine.lol\/apelife\/index.html&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251217014717\/https:\/\/justine.lol\/apelife\/index.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:12:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 22:35:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:04:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 18:47:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:50:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:41:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 00:55:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 03:54:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 09:28:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 00:59:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 11:13:32&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 11:13:32&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:141,&quot;href&quot;:&quot;https:\/\/justine.lol\/cosmopolitan\/index.html&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260108170210\/https:\/\/justine.lol\/cosmopolitan\/index.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:13:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 18:47:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:50:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:41:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 00:55:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 03:54:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 09:28:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 00:59:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 11:13:44&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 11:13:44&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-2793" src="https://learncgames.com/wp-content/uploads/2021/02/apelife-300x217.png" alt="apelife" width="300" height="217" srcset="https://learncgames.com/wp-content/uploads/2021/02/apelife-300x217.png 300w, https://learncgames.com/wp-content/uploads/2021/02/apelife.png 511w" sizes="auto, (max-width: 300px) 100vw, 300px" />I&#8217;ve <a title="Link to blog entry on Life" href="https://learncgames.com/john-conways-game-of-life/" target="_blank" rel="nofollow noopener">mentioned Life before</a>, this is the cellular automata as discovered by John Horton Conway. It&#8217;s perhaps less of a game and more of a recreation for anyone fascinated by programming. It&#8217;s hard to add up how many man-hours have been spent on it.</p>
<p>Developer Justine Tunney (<em>aka Jart on Github</em>) has developed a portable Life called <a title="Link to apelife" href="https://justine.lol/apelife/index.html" target="_blank" rel="nofollow noopener">Apelife.</a> Portable as in it can run on Windows (graphically) and Linux (Text User Interface). The application is a modest 112 KB in size and is one of the fastest I&#8217;ve seen. When you have a large area and gliders whizz across it, you know its fast.</p>
<p>She is also the author of <a title="Link to Cosmopolitan C" href="https://justine.lol/cosmopolitan/index.html" target="_blank" rel="nofollow noopener">Cosmopolitan C</a> which Apelife uses.  It lets gcc outputs portable binaries that will run on every Linux distro in addition to Mac OS X, Windows NT, FreeBSD, OpenBSD, and NetBSD. It&#8217;s rather ingenious.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/portable-life-in-c/">Portable Life in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2791</post-id>	</item>
		<item>
		<title>Some Pretty fractals in C + SDL2</title>
		<link>https://learncgames.com/some-pretty-fractals-in-c-sdl2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=some-pretty-fractals-in-c-sdl2</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 17 Feb 2021 00:00:17 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[fractals]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2693</guid>

					<description><![CDATA[<p>If you&#8217;ve ever wanted to draw fractals in C, here&#8217;s some code for you. These come from Misha on his(her?) GitHub page.  There are three as you can see. Each has their own program &#8211; barnsley.c, sierpinski.c and y-fractal.c. All three programs create an SDL2 window then display the image. Note that this was coded [&#8230;]</p>
The post <a href="https://learncgames.com/some-pretty-fractals-in-c-sdl2/">Some Pretty fractals in C + SDL2</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:169,&quot;href&quot;:&quot;https:\/\/en.wikipedia.org\/wiki\/Fractal&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260202132608\/https:\/\/en.wikipedia.org\/wiki\/Fractal&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:22:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-18 23:29:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 13:54:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-07 12:12:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 08:10:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 18:47:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-23 14:05:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 21:41:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-01 04:48:36&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-08 03:54:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 06:00:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-18 04:18:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 02:34:37&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 02:34:37&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:170,&quot;href&quot;:&quot;https:\/\/github.com\/mikh86\/sdl-fractals&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20201205110601\/https:\/\/github.com\/mikh86\/sdl-fractals&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:23:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 23:29:24&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-24 13:54:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-07 12:12:47&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 08:10:08&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-17 18:47:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-23 14:05:58&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-27 21:41:33&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-01 04:48:36&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 03:54:31&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-13 13:17:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-18 04:18:30&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-22 02:34:39&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 02:34:39&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_2694" aria-describedby="caption-attachment-2694" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-2694" src="https://learncgames.com/wp-content/uploads/2021/02/fractals-300x286.png" alt="Fractals" width="300" height="286" srcset="https://learncgames.com/wp-content/uploads/2021/02/fractals-300x286.png 300w, https://learncgames.com/wp-content/uploads/2021/02/fractals.png 696w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-2694" class="wp-caption-text">Code by Misha</figcaption></figure>
<p>If you&#8217;ve ever wanted to draw <a title="Link to fractal on Wikipedia" href="https://en.wikipedia.org/wiki/Fractal" target="_blank" rel="noopener">fractals</a> in C, here&#8217;s some code for you. These come from Misha on his(<em>her?</em>) <a title="Link to sdl-fractals on GitHub" href="https://github.com/mikh86/sdl-fractals" target="_blank" rel="nofollow noopener">GitHub</a> page.  There are three as you can see. Each has their own program &#8211; barnsley.c, sierpinski.c and y-fractal.c. All three programs create an SDL2 window then display the image.</p>
<p>Note that this was coded for Linux. I modified the programs so they would run on Windows and the screenshot was done from my machine. I know these images are on the GitHub page.</p>
<p>If you want to compile and run, then on all three programs change the SDL include from</p>
<pre>#include &lt;SDL2/SDL.h&gt;</pre>
<p>to</p>
<pre>#include "SDL.h"</pre>
<p>Also with the barnsley.c you need to give initial values to mx and my in the <strong>renderFractals()</strong> function (lines 88 and 89) and change these two lines: (<em>114 and 115</em>). No other changes are needed to let them compile.</p>
<pre><code class="language-c" data-line="">
mx_c = mx - win_w / 2;
my_c = my - win_h / 2;
</code>  to<code class="language-c" data-line="">
mx_c = mx - WIDTH / 2;
my_c = my - HEIGHT / 2;</code></pre>The post <a href="https://learncgames.com/some-pretty-fractals-in-c-sdl2/">Some Pretty fractals in C + SDL2</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2693</post-id>	</item>
		<item>
		<title>DungeonRush &#8211; open source C + SDL 2 game</title>
		<link>https://learncgames.com/dungeonrush-open-source-c-sdl-2-game/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dungeonrush-open-source-c-sdl-2-game</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 10 Feb 2021 00:00:15 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[arcade]]></category>
		<category><![CDATA[game]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2642</guid>

					<description><![CDATA[<p>I continue my quest, looking around for open source games in C that use SDL 2. The latest one is DungeonRush by developer Rapiz1 (does no one ever use their real names these days?) who hails from Wuhan. It is not a rogue-like, but more a Snake-like game.   You move your hero around the playing [&#8230;]</p>
The post <a href="https://learncgames.com/dungeonrush-open-source-c-sdl-2-game/">DungeonRush – open source C + SDL 2 game</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:188,&quot;href&quot;:&quot;https:\/\/github.com\/Rapiz1\/DungeonRush&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250214145114\/https:\/\/github.com\/rapiz1\/DungeonRush&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:31:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 20:55:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 22:35:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 13:54:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-22 05:50:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 06:51:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 11:07:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 05:32:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 05:20:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 08:10:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 02:10:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 10:00:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 03:35:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 15:59:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 00:44:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 18:58:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 20:30:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 01:56:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 09:51:17&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 09:51:17&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-2644 size-medium" src="https://learncgames.com/wp-content/uploads/2021/02/dungeonrush-1-300x207.png" alt="DungeonRush game" width="300" height="207" srcset="https://learncgames.com/wp-content/uploads/2021/02/dungeonrush-1-300x207.png 300w, https://learncgames.com/wp-content/uploads/2021/02/dungeonrush-1.png 544w" sizes="auto, (max-width: 300px) 100vw, 300px" />I continue my quest, looking around for open source games in C that use SDL 2. The latest one is <a title="Link to DungeonRush on GitHub" href="https://github.com/Rapiz1/DungeonRush" target="_blank" rel="nofollow noopener">DungeonRush</a> by developer Rapiz1 (<em>does no one ever use their real names these days?</em>) who hails from Wuhan.</p>
<p>It is not a rogue-like, but more a Snake-like game.   You move your hero around the playing area avoiding monsters and things fired at you while picking up stuff and people to give you extra lives.  As well as the difficulty levels it includes multiplayer mode as well though I haven&#8217;t tried that.</p>
<p>If you are learning C or games programming, it&#8217;s worth studying to see how others do things; this includes its own text drawing and high scoring and saving high scores.  It&#8217;s quite fun to play though I am rubbish playing it, even at the normal level. I&#8217;ve added this to the C Code links page. (<em>Accessed on the top menu</em>),</p>
<p>Snake games are interesting because if you use a circular buffer, no matter how big the snake grows, you can move it by just moving the head and tail elements. An O(1) operation!</p>The post <a href="https://learncgames.com/dungeonrush-open-source-c-sdl-2-game/">DungeonRush – open source C + SDL 2 game</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2642</post-id>	</item>
		<item>
		<title>Timing of SDL vs TTF fonts</title>
		<link>https://learncgames.com/timing-of-sdl-vs-ttf-fonts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=timing-of-sdl-vs-ttf-fonts</link>
					<comments>https://learncgames.com/timing-of-sdl-vs-ttf-fonts/#comments</comments>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 05 Dec 2020 00:00:28 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[timing]]></category>
		<category><![CDATA[ttf.sdl]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1975</guid>

					<description><![CDATA[<p>So I got round to writing that SDL vs TTF timing comparison. However I had to make a few assumptions. The program was written for Windows but easily converts to Linux (apart from the timing code but I did that back in March for Linux) is about 250 lines long. I&#8217;ve uploaded it to GitHub, [&#8230;]</p>
The post <a href="https://learncgames.com/timing-of-sdl-vs-ttf-fonts/">Timing of SDL vs TTF fonts</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:13,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnC&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250807013721\/https:\/\/github.com\/David-H-Bolton\/LearnC&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:40:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 18:24:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 22:16:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 22:19:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 22:22:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 04:17:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:17:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 04:22:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 04:38:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 08:48:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 09:17:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 10:18:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 12:43:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 15:14:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:19:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 16:38:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 19:05:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 22:49:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 04:18:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 04:19:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 09:53:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 10:17:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 13:35:54&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-21 15:50:44&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 15:50:44&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:342,&quot;href&quot;:&quot;https:\/\/www.libsdl.org\/projects\/SDL_ttf&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260203013147\/https:\/\/www.libsdl.org\/projects\/SDL_ttf\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:11:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 08:45:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 09:27:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 20:03:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 12:06:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 15:37:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:34:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 17:50:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 07:52:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 21:40:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 22:50:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 06:25:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 16:36:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 19:27:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:41:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 01:44:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 13:20:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 00:37:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 06:01:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 08:55:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 17:40:48&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 17:40:48&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-1976" src="https://learncgames.com/wp-content/uploads/2020/12/timings.png" alt="Timings" width="649" height="325" srcset="https://learncgames.com/wp-content/uploads/2020/12/timings.png 649w, https://learncgames.com/wp-content/uploads/2020/12/timings-300x150.png 300w" sizes="auto, (max-width: 649px) 100vw, 649px" />So I got round to writing that SDL vs TTF timing comparison. However I had to make a few assumptions. The program was written for Windows but easily converts to Linux (<em>apart from the timing code but I did that <a title="Compiling Linux timing code" href="https://learncgames.com/that-clang-c-compilation/" target="_blank" rel="nofollow noopener noreferrer">back in March</a> for Linux</em>) is about 250 lines long. I&#8217;ve uploaded it to <a title="Link to LearnC on GitHub" href="https://github.com/David-H-Bolton/LearnC" target="_blank" rel="nofollow noopener noreferrer">GitHub</a>, and the zip file contains not only the VS 2019 project and source but all the SDL2 dlls plus a free font MONOFONT.TTF (renamed to font.ttf) and test.png which is the bitmap font as a .png file.</p>
<p>Note you&#8217;ll have to edit the <strong>sdlttf.c</strong> file and change the paths to load the font .png and ttf files in lines 96 and 97.</p>
<p>I&#8217;d never used <a title="Link to SDL_ttf on libsdl.org" href="https://www.libsdl.org/projects/SDL_ttf/" target="_blank" rel="nofollow noopener noreferrer">SDL_ttf</a> before though it worked out easy enough. There are three levels of TTF &#8211; fast, not so fast and slow but pretty. I went for the fastest setting. The SDL text is in red and the TTF in yellow and are roughly the same height about 30 points.</p>
<p>If you read the caption you&#8217;ll see that my bitmap font drawing (I call it SDL) is nearly 14 x slower than TTF. In my code I prerendered the phrase &#8220;Sphinx of black quartz, judge my vow&#8221; which has all 26 letters a-z but is shorter than standard phrase &#8220;the lazy quick fox&#8230;&#8221;.</p>
<p>SDL_ttf renders the phrase into a <strong>surface</strong> which is a memory structure in RAM. Calling <strong>SDL_CreateTextureFromSurface</strong> (line 188) creates a texture from this (it copies the bitmap from RAM to VRAM) and so in my program I was just blitting this texture to the screen. The SDL printing in the <strong>print</strong> function (Line 157) gets each character, and calls <strong>printch</strong> (line 143) which works out where in the <strong>textFont</strong> texture that character and blits it. I&#8217;m guessing the overhead of blitting individual characters is what makes it so much slower.</p>
<p>So for fixed phrases where you can prerender the surface and texture, SDL_ttf is way faster and more flexible with colour and to a certain extent size. Colour is set at runtime while size is set when you prerender the font into the surface. If you want different sizes then you need multiple surfaces and corresponding textures for each size. Things like say a score would be a bit slower because it would need to be rendered each time and copied to a texture or prerender all 10 digits and have a texture for each and draw it much like the print method does.</p>
<p>The program is a little rough in places; it was thrown together over three nights.</p>The post <a href="https://learncgames.com/timing-of-sdl-vs-ttf-fonts/">Timing of SDL vs TTF fonts</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://learncgames.com/timing-of-sdl-vs-ttf-fonts/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1975</post-id>	</item>
		<item>
		<title>Quicksort in C</title>
		<link>https://learncgames.com/quicksort-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quicksort-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 12 Nov 2020 00:00:55 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[bubble sort]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[sort]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1783</guid>

					<description><![CDATA[<p>Normally I wouldn&#8217;t mention a sorting algorithm, but by a lucky coincidence, when I had my interview before going to university (Queen&#8217;s University Belfast), the bloke who interviewed me back in 1977 was the inventor of Quicksort. Tony Hoare. He left very shortly after so I never got him as a lecturer, As algorithms go, [&#8230;]</p>
The post <a href="https://learncgames.com/quicksort-in-c/">Quicksort in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:384,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/clker-free-vector-images-3736\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=27489&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260115073407\/https:\/\/pixabay.com\/users\/clker-free-vector-images-3736\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:34:33&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-04 20:39:21&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-13 19:34:24&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:34:56&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-02 21:43:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-06 06:03:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 05:59:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-16 05:32:15&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-19 12:46:34&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 12:46:34&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:385,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=27489&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:34:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-04 20:39:18&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-13 19:34:26&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:34:58&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-02 21:43:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-06 06:03:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 05:59:56&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-16 05:32:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-19 12:46:35&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 12:46:35&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:386,&quot;href&quot;:&quot;https:\/\/en.wikipedia.org\/wiki\/Quicksort&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260203173924\/https:\/\/en.wikipedia.org\/wiki\/Quicksort&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:34:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 22:35:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 20:39:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-13 19:34:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 21:35:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-02 21:43:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-06 06:03:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-12 05:59:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-19 12:46:34&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 12:46:34&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:387,&quot;href&quot;:&quot;https:\/\/www.geeksforgeeks.org\/quick-sort&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20240606210354\/https:\/\/www.geeksforgeeks.org\/quick-sort\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:34:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:04:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 20:39:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 19:34:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:35:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 21:43:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 06:03:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 06:00:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-19 12:46:35&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 12:46:35&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:388,&quot;href&quot;:&quot;https:\/\/www.geeksforgeeks.org\/bubble-sort&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20240616094333\/https:\/\/www.geeksforgeeks.org\/bubble-sort\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:34:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:04:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 20:39:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 19:34:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:34:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 21:43:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 06:03:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 05:59:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 05:32:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-19 12:46:35&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 12:46:35&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:119,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnCCode&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250213114359\/https:\/\/github.com\/David-H-Bolton\/LearnCCode&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:59:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 22:04:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 22:42:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 03:42:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-23 00:07:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 22:28:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 01:11:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 06:32:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 23:28:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 21:49:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 21:29:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 12:52:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 03:59:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 22:58:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 00:56:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 04:43:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 12:23:33&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 12:23:33&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1786" aria-describedby="caption-attachment-1786" style="width: 271px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-1786" src="https://learncgames.com/wp-content/uploads/2020/11/sort-27489_640-271x300.png" alt="Sorting" width="271" height="300" srcset="https://learncgames.com/wp-content/uploads/2020/11/sort-27489_640-271x300.png 271w, https://learncgames.com/wp-content/uploads/2020/11/sort-27489_640.png 579w" sizes="auto, (max-width: 271px) 100vw, 271px" /><figcaption id="caption-attachment-1786" class="wp-caption-text">Image by <a href="https://pixabay.com/users/clker-free-vector-images-3736/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=27489">Clker-Free-Vector-Images</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=27489">Pixabay</a></figcaption></figure>
<p>Normally I wouldn&#8217;t mention a sorting algorithm, but by a lucky coincidence, when I had my interview before going to university (<em>Queen&#8217;s University Belfast</em>), the bloke who interviewed me back in 1977 was the inventor of <a title="Link to Wikipedia on Quicksort" href="https://en.wikipedia.org/wiki/Quicksort" target="_blank" rel="nofollow noopener noreferrer">Quicksort</a>. Tony Hoare. He left very shortly after so I never got him as a lecturer,</p>
<p>As algorithms go, Quicksort is one of the faster. it works by splitting the list in two and then recursively sorting the two halves. The simplest sorting method Bubble sort uses a double loop and for very small numbers of items to sort is generally more efficient than Quicksort, but it doesn&#8217;t take long for Quicksort to catch up.</p>
<p>I was reminded of Quicksort by seeing<a title="Link to C implementation of Quicksort" href="https://www.geeksforgeeks.org/quick-sort/" target="_blank" rel="nofollow noopener noreferrer"> this article</a> and thought it would be interesting to do a series of test of sorting 5-50 items a few thousand times each in Quicksort and Bubblesort and see where the crossover point is. How many items is the minimum for Quicksort to become faster than Bubble sort?</p>
<p>If you take the Swap functions and BubbleSort from <a title="Link to C BubbleSort" href="https://www.geeksforgeeks.org/bubble-sort/" target="_blank" rel="nofollow noopener noreferrer">here</a> and partition and quickSort functions from <a title="Link to Qiuicksort" href="https://www.geeksforgeeks.org/quick-sort/" target="_blank" rel="nofollow noopener noreferrer">here</a> and use my high precision timing code and add the code below then you can run the comparison. I did it twice, once in Debug and once in Release and the difference is much larger in release. I&#8217;ve zipped up the source code including the Visual C++ project code (<em>It is C source code not C++ btw</em>) and high performance timing code and put it <a title="Link to Sort comparison code on GitHub" href="https://github.com/David-H-Bolton/LearnCCode" target="_blank" rel="nofollow noopener noreferrer">on GitHub</a>.</p>
<pre><code class="language-c" data-line="">#define NUMLOOPS 5000

int main()
{
    int startarr[]= { 86,91,50,5,79,64,2,57,26,63,12,61,12,92,40,38,11,
                 94,90,38,24,25,54,75,67,56,7,9,32,26,54,48,51,28,
                90,50,37,53,8,75,30,25,59,57,92,42,25,33,84,46 };
    int arr[50];
    stopWatch stw;
    double bTime, qTime;

    bTime = 0.0;
    qTime = 0.0;
    for (int i = 3; i &lt; 50; i++) {
        printf(&quot;Bubble sort for %d = &quot;, i);
        for (int j = 1; j &lt; NUMLOOPS; j++) {
            memset(arr, 0, sizeof(arr));                     // Clear arr
            memcpy(arr, startarr, sizeof(int) * i); // copy in i elements
            startTimer(&amp;stw);
            bubbleSort(arr, i);
            stopTimer(&amp;stw);
            bTime += getElapsedTime(&amp;stw);
        }
        bTime /= NUMLOOPS;
        printf(&quot;%12.10f.  &quot;, bTime);
        printf(&quot;Quicksort sort for %d = &quot;, i);
        for (int j = 1; j &lt; NUMLOOPS; j++) {
            memcpy(arr, startarr, sizeof(int) * i); // copy in i elements
            startTimer(&amp;stw);
            quickSort(arr, 0, i - 1);
            stopTimer(&amp;stw);
            qTime += getElapsedTime(&amp;stw);
        }
        qTime /= NUMLOOPS;
        printf(&quot;%12.10f\n&quot;, qTime);
    }
    return 0;
}</code></pre>
<p>These are the first 15 and last 5 output lines in Release. The Bubble sort time for 7 is a bit of an oddity just for the actual numbers sorted. But its clear that by 11 values that Bubble sort is slower than QuickSort and the difference just gets worse up to 50. So up to 10 elements, Bubble Sort wins.</p>
<pre><code class="language-c" data-line="">Bubble sort for 3 = 0.0000000358.  Quicksort sort for 3 = 0.0000000412
Bubble sort for 4 = 0.0000000407.  Quicksort sort for 4 = 0.0000000445
Bubble sort for 5 = 0.0000000474.  Quicksort sort for 5 = 0.0000000485
Bubble sort for 6 = 0.0000000677.  Quicksort sort for 6 = 0.0000000448
Bubble sort for 7 = 0.0000000191.  Quicksort sort for 7 = 0.0000000097
Bubble sort for 8 = 0.0000000405.  Quicksort sort for 8 = 0.0000000601
Bubble sort for 9 = 0.0000000510.  Quicksort sort for 9 = 0.0000000434
Bubble sort for 10 = 0.0000000568.  Quicksort sort for 10 = 0.0000000653
Bubble sort for 11 = 0.0000000633.  Quicksort sort for 11 = 0.0000000566
Bubble sort for 12 = 0.0000000702.  Quicksort sort for 12 = 0.0000000606
Bubble sort for 13 = 0.0000000845.  Quicksort sort for 13 = 0.0000000743
Bubble sort for 14 = 0.0000000931.  Quicksort sort for 14 = 0.0000001145
Bubble sort for 15 = 0.0000001040.  Quicksort sort for 15 = 0.0000000827
Bubble sort for 16 = 0.0000001142.  Quicksort sort for 16 = 0.0000000892
Bubble sort for 17 = 0.0000001448.  Quicksort sort for 17 = 0.0000000974
...
Bubble sort for 45 = 0.0000008478.  Quicksort sort for 45 = 0.0000002737
Bubble sort for 46 = 0.0000008561.  Quicksort sort for 46 = 0.0000002524
Bubble sort for 47 = 0.0000008948.  Quicksort sort for 47 = 0.0000002643
Bubble sort for 48 = 0.0000009421.  Quicksort sort for 48 = 0.0000003147
Bubble sort for 49 = 0.0000010042.  Quicksort sort for 49 = 0.0000002804</code></pre>
<p>&nbsp;</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/quicksort-in-c/">Quicksort in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1783</post-id>	</item>
		<item>
		<title>Can you compile this?</title>
		<link>https://learncgames.com/can-you-compile-this/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=can-you-compile-this</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 07 Nov 2020 00:00:03 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[C11]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1733</guid>

					<description><![CDATA[<p>It&#8217;s just a little bit of C. I compiled it with these three compilers. MS VC (16.7.7 on Windows) gcc, and clang on Ubuntu 20.04 LTS. MS VC picked up the _Noreturn and complained, gcc 9.33 compiled it with not a whisper while clang 10.0.0 warned about void in the main function but compiled it [&#8230;]</p>
The post <a href="https://learncgames.com/can-you-compile-this/">Can you compile this?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:402,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/publicdomainpictures-14\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=21849&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260201001249\/https:\/\/pixabay.com\/users\/publicdomainpictures-14\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:08&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 00:57:50&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-23 00:07:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-04 22:26:50&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-10 14:16:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-17 18:47:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:41:48&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-07 19:21:43&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-13 06:00:58&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-18 18:06:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 02:34:42&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 02:34:42&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:403,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=21849&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:11&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 00:57:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-23 00:07:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 11:04:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-04 22:26:50&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-10 14:16:21&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-17 18:47:38&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:41:48&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-07 19:21:43&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-13 06:00:51&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-18 18:06:43&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 02:34:41&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 02:34:41&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:404,&quot;href&quot;:&quot;https:\/\/devblogs.microsoft.com\/cppblog\/c11-and-c17-standard-support-arriving-in-msvc&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251212150650\/https:\/\/devblogs.microsoft.com\/cppblog\/c11-and-c17-standard-support-arriving-in-msvc\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:18&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 22:18:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-15 11:07:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-18 18:46:19&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-23 00:07:13&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 04:02:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 22:26:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-08 08:26:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-11 09:12:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 09:33:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 16:37:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 19:32:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 21:41:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 05:56:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-07 19:21:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-12 12:53:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-16 05:32:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-20 04:42:29&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 04:42:29&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1734" aria-describedby="caption-attachment-1734" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-1734" src="https://learncgames.com/wp-content/uploads/2020/11/books-21849_640-300x200.jpg" alt="No return" width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2020/11/books-21849_640-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2020/11/books-21849_640.jpg 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1734" class="wp-caption-text">Image by <a href="https://pixabay.com/users/publicdomainpictures-14/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=21849">PublicDomainPictures</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=21849">Pixabay</a></figcaption></figure>
<p>It&#8217;s just a little bit of C. I compiled it with these three compilers. MS VC (<em>16.7.7 on Windows</em>) gcc, and clang on Ubuntu 20.04 LTS. MS VC picked up the _Noreturn and complained, gcc 9.33 compiled it with not a whisper while clang 10.0.0 warned about void in the main function but compiled it anyway.</p>
<p>Both the clang and gcc compiled files ran and as you&#8217;d expect sat in an infinite loop until I control-c&#8217;d it.</p>
<p>However soon MS VC will compile it. According to<a title="Link to Blog about MS VC support for C11" href="https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/" target="_blank" rel="nofollow noopener noreferrer"> this blog entry,</a> MSVC from 16.8 preview 3 supports C11 and the _Noreturn feature (<em>which tells the compiler that the function never returns</em>) will be ok. Both gcc and clang support C11 so no problems.</p>
<pre><code class="language-c" data-line="">#include &lt;stdio.h&gt;

_Noreturn void nrloop() {
	while (1) {
		;
	}
}

void main() {
	nrloop();
}</code></pre>
<p>&nbsp;</p>
<p>When would I use such a function, you might ask. IO can&#8217;t see me using it much unless I wnt to write a background thread function that just runs forever. I have indeed written such a function recently but it was in Delphi not C. Another use is a function that exits perhaps vi a jmp. It also lets the compiler know so it can optimize return code away.</p>
<p>As I said, I don&#8217;t think I&#8217;ll be using it much if at all.</p>The post <a href="https://learncgames.com/can-you-compile-this/">Can you compile this?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1733</post-id>	</item>
		<item>
		<title>So what do you think this code does?</title>
		<link>https://learncgames.com/so-what-do-you-think-this-code-does/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=so-what-do-you-think-this-code-does</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 05 Nov 2020 00:00:24 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[fast inverse square root]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1721</guid>

					<description><![CDATA[<p>Here&#8217;s a little C function. It&#8217;s not exactly intuitive what it does and I&#8217;ve renamed it to prevent giving it away. float mystery( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &#38;y; i = [&#8230;]</p>
The post <a href="https://learncgames.com/so-what-do-you-think-this-code-does/">So what do you think this code does?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:406,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/pixapopz-2873171\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:407,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:31&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-22 16:29:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-03 12:55:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 12:22:23&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-14 09:32:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-20 15:40:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:41:50&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 18:25:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-09 05:44:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-13 13:17:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-19 22:45:05&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 22:45:05&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:408,&quot;href&quot;:&quot;https:\/\/www.beyond3d.com\/content\/articles\/8&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251230093552\/https:\/\/www.beyond3d.com\/content\/articles\/8\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 22:35:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-22 16:29:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 11:04:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-03 12:55:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-09 12:22:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 09:33:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 15:41:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 21:42:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 18:25:17&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-09 05:44:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 13:17:40&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-18 18:06:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 02:34:47&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 02:34:47&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1722" aria-describedby="caption-attachment-1722" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-1722" src="https://learncgames.com/wp-content/uploads/2020/11/math-1500720_640-300x168.jpg" alt="Math(s) symbols" width="300" height="168" srcset="https://learncgames.com/wp-content/uploads/2020/11/math-1500720_640-300x168.jpg 300w, https://learncgames.com/wp-content/uploads/2020/11/math-1500720_640.jpg 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1722" class="wp-caption-text">Image by <a href="https://pixabay.com/users/pixapopz-2873171/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720">Chuk Yong</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720">Pixabay</a></figcaption></figure>
<p>Here&#8217;s a little C function. It&#8217;s not exactly intuitive what it does and I&#8217;ve renamed it to prevent giving it away.</p>
<pre><code class="language-c" data-line="">  float mystery( float number )
  {
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &amp;y;                       
    i  = 0x5f3759df - ( i &gt;&gt; 1 );               
    y  = * ( float * ) &amp;i;
    y  = y * ( threehalfs - ( x2 * y * y ) );   
    return y;
  }</code></pre>
<p>If it helps, this line is really the heart of it.</p>
<pre><code class="language-c" data-line="">    i  = 0x5f3759df - ( i &gt;&gt; 1 );  </code></pre>
<p>Mystified? Well it&#8217;s a fast inverse square root. No one really knows who wrote it though John Carnack of Quake and Doom fame popularised it. There&#8217;s an <a title="Link to discussion abouty the author of the fast inverse square root" href="https://www.beyond3d.com/content/articles/8/" target="_blank" rel="nofollow noopener noreferrer">interesting discussion about the author</a> but no one really knows.</p>
<p>There&#8217;s less need for this type of thing nowadays because of all the fast silicon but back 20-25 years ago when graphics processors were in their very infancy, it was a highly useful optimization. Mind you , you&#8217;d need to know assembly language inside out to come up with stuff like this.</p>The post <a href="https://learncgames.com/so-what-do-you-think-this-code-does/">So what do you think this code does?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1721</post-id>	</item>
	</channel>
</rss>
