<?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>celsobarriga-dot-com &#187; C</title>
	<atom:link href="http://www.celsobarriga.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.celsobarriga.com</link>
	<description>Wasting bandwidth in style!</description>
	<lastBuildDate>Sun, 06 Nov 2011 21:27:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Read string from stdin using fgets</title>
		<link>http://www.celsobarriga.com/2009/02/26/read-string-from-stdin-using-fgets/</link>
		<comments>http://www.celsobarriga.com/2009/02/26/read-string-from-stdin-using-fgets/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 19:44:37 +0000</pubDate>
		<dc:creator>celso</dc:creator>
				<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://www.celsobarriga.com/?p=80</guid>
		<description><![CDATA[#include &#60;stdio.h> #include &#60;string.h> int main(void) { char str[80]; int i; printf("Enter a string: "); fgets(str, 10, stdin); /* remove newline, if present */ i = strlen(str)-1; if( str[ i ] == '\n') str[i] = '\0'; printf("This is your string: %s", str); return 0; }]]></description>
			<content:encoded><![CDATA[<pre style='color:#000000;background:#ffffff;'><span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>stdio.h</span><span style='color:#800000; '>></span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>string.h</span><span style='color:#800000; '>></span>

<span style='color:#800000; font-weight:bold; '>int</span> <span style='color:#400000; '>main</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>void</span><span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
  <span style='color:#800000; font-weight:bold; '>char</span> str<span style='color:#808030; '>[</span><span style='color:#008c00; '>80</span><span style='color:#808030; '>]</span><span style='color:#800080; '>;</span>
  <span style='color:#800000; font-weight:bold; '>int</span> i<span style='color:#800080; '>;</span>

  printf<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Enter a string: </span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
  fgets<span style='color:#808030; '>(</span>str<span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> <span style='color:#603000; '>stdin</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

  <span style='color:#696969; '>/* remove newline, if present */</span>
  i <span style='color:#808030; '>=</span> strlen<span style='color:#808030; '>(</span>str<span style='color:#808030; '>)</span><span style='color:#808030; '>-</span><span style='color:#008c00; '>1</span><span style='color:#800080; '>;</span>
  <span style='color:#800000; font-weight:bold; '>if</span><span style='color:#808030; '>(</span> str<span style='color:#808030; '>[</span> i <span style='color:#808030; '>]</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'\n'</span><span style='color:#808030; '>)</span>
      str<span style='color:#808030; '>[</span>i<span style='color:#808030; '>]</span> <span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'\0'</span><span style='color:#800080; '>;</span>

  printf<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>This is your string: </span><span style='color:#0f69ff; '>%s</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> str<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

  <span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.celsobarriga.com/2009/02/26/read-string-from-stdin-using-fgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

