<?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>fprintf | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/fprintf/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>Sat, 31 Dec 2022 18:43:13 +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>fprintf | 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>How to debug programs using SDL</title>
		<link>https://learncgames.com/how-to-debug-programs-using-sdl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-debug-programs-using-sdl</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 01 Jan 2023 00:00:51 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[fprintf]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3174</guid>

					<description><![CDATA[<p>There&#8217;s nothing worse than a program halting with a simple &#8220;Segmentation fault&#8221; and no idea where or why. It happened to me today working on the 2nd eBook (for Raspberry Pi) and I had to figure out where it was going wrong. In the end it was a really silly bug, I was trying to [&#8230;]</p>
The post <a href="https://learncgames.com/how-to-debug-programs-using-sdl/">How to debug programs using SDL</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;:35,&quot;href&quot;:&quot;https:\/\/www.educba.com\/stderr-in-c&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206111555\/https:\/\/www.educba.com\/stderr-in-c\/&quot;,&quot;redirect_href&quot;:&quot;https:\/\/www.educba.com\/stderr-in-c\/&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 22:25:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 08:53:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 20:32:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 13:34:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-21 07:08:05&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-24 21:19:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-28 13:10:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 05:12:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-09 21:59:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-15 12:33:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-21 03:40:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 15:23:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-29 10:24:48&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-01 20:14:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 02:03:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-08 11:16:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-11 14:30:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-15 09:28:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-19 12:07:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 14:23:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-28 11:16:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-02 00:14:50&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-02 00:14:50&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="alignleft size-full wp-image-3176" src="https://learncgames.com/wp-content/uploads/2023/01/fprintf.png" alt="Terminal fprintf output" width="373" height="117" srcset="https://learncgames.com/wp-content/uploads/2023/01/fprintf.png 373w, https://learncgames.com/wp-content/uploads/2023/01/fprintf-300x94.png 300w" sizes="(max-width: 373px) 100vw, 373px" />There&#8217;s nothing worse than a program halting with a simple &#8220;Segmentation fault&#8221; and no idea where or why. It happened to me today working on the 2nd eBook (for Raspberry Pi) and I had to figure out where it was going wrong.</p>
<p>In the end it was a really silly bug, I was trying to load masks but had left the <strong>masks/</strong> folder out of the filename.</p>
<p>How did I find it? I sprinkled a few <strong>fprintf(stderr,&#8221;message&#8221;);</strong> throughout the program changing &#8220;message&#8221; to something appropriate and launched it from a terminal. I&#8217;d thought it was in a function <strong>LoadTextures()</strong> so added a call before and after but you can see that worked and the segmentation fault happened <em>after</em> <strong>LoadTextures()</strong>.</p>
<p>So I added it before and after <strong>LoadMasks()</strong> and my second run it happened before it reached the <strong>After LoadMasks</strong> message.</p>
<p>Note, I used <strong>stderr</strong> as the output path because, unlike <strong>stdout</strong> which is buffered and can be cleared, anything sent to <strong>stderr</strong> appears immediately.  More about this in this <a title="Link to article about stderr" href="https://www.educba.com/stderr-in-c/" target="_blank" rel="nofollow noopener">offsite article</a>.</p>
<p>The <strong>using SDL</strong> part of the title is just to show that you can find bugs even in programs that use SDL.</p>The post <a href="https://learncgames.com/how-to-debug-programs-using-sdl/">How to debug programs using SDL</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">3174</post-id>	</item>
	</channel>
</rss>
