<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: C Tutorial &#8211; The functions malloc and free</title>
	<atom:link href="http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free</link>
	<description>CodingUnit is your online resource for learning to program. Tutorials on C, C++, PHP, Python, MySQL, Java, JQuery, Opengl, DirectX and much more!</description>
	<lastBuildDate>Mon, 06 Feb 2012 06:08:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Deepak</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-4420</link>
		<dc:creator>Deepak</dc:creator>
		<pubDate>Sat, 14 Jan 2012 19:32:59 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-4420</guid>
		<description>good</description>
		<content:encoded><![CDATA[<p>good</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: neeraj</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-4184</link>
		<dc:creator>neeraj</dc:creator>
		<pubDate>Mon, 14 Nov 2011 20:34:31 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-4184</guid>
		<description>thanks........</description>
		<content:encoded><![CDATA[<p>thanks&#8230;&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-3674</link>
		<dc:creator>Joseph</dc:creator>
		<pubDate>Wed, 10 Aug 2011 21:11:23 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-3674</guid>
		<description>I am attempting to read in data from a csv file with two columns: the first I am reading in as character string; the second column as a float. The column headers have been removed. I represent each row as atruct rec; the entire data should then be represented by an array of structs. My problem is that in the while loop I get segment fault when attempting to read the first row. Can anyone see why? Thanks.

#include 
#include 
#define MAXROWS 400

struct rec{
	char *date;
	float *yld;
};

struct rec *readFile();

/* read the input file */
struct rec *readFile(char *filname){
	FILE *fp;
	char *line;
	struct rec rw;
	int i=0;
	struct rec *data[MAXROWS];
	for(i = 0; i &lt; MAXROWS; i++){
		data[i] = (struct rec *)malloc(sizeof(struct rec));
	}
	i = 0;
	rw = *data[0];
	if((fp = fopen(filname, &quot;r&quot;)) != NULL){
		while(fscanf(fp, &quot;%s,%f&quot;, rw.date, rw.yld) == 2){
			i++;
			rw = *data[i];
		}
		return data;
	}else{
		exit(1);
	}
	return NULL;
}

int main(){

	struct rec *data;
	data = readFile(&quot;temp_test.csv&quot;);
	return 0;
}</description>
		<content:encoded><![CDATA[<p>I am attempting to read in data from a csv file with two columns: the first I am reading in as character string; the second column as a float. The column headers have been removed. I represent each row as atruct rec; the entire data should then be represented by an array of structs. My problem is that in the while loop I get segment fault when attempting to read the first row. Can anyone see why? Thanks.</p>
<p>#include<br />
#include<br />
#define MAXROWS 400</p>
<p>struct rec{<br />
	char *date;<br />
	float *yld;<br />
};</p>
<p>struct rec *readFile();</p>
<p>/* read the input file */<br />
struct rec *readFile(char *filname){<br />
	FILE *fp;<br />
	char *line;<br />
	struct rec rw;<br />
	int i=0;<br />
	struct rec *data[MAXROWS];<br />
	for(i = 0; i &lt; MAXROWS; i++){<br />
		data[i] = (struct rec *)malloc(sizeof(struct rec));<br />
	}<br />
	i = 0;<br />
	rw = *data[0];<br />
	if((fp = fopen(filname, &quot;r&quot;)) != NULL){<br />
		while(fscanf(fp, &quot;%s,%f&quot;, rw.date, rw.yld) == 2){<br />
			i++;<br />
			rw = *data[i];<br />
		}<br />
		return data;<br />
	}else{<br />
		exit(1);<br />
	}<br />
	return NULL;<br />
}</p>
<p>int main(){</p>
<p>	struct rec *data;<br />
	data = readFile(&quot;temp_test.csv&quot;);<br />
	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vimal</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-3554</link>
		<dc:creator>vimal</dc:creator>
		<pubDate>Tue, 28 Jun 2011 04:06:50 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-3554</guid>
		<description>char *TTLSnote = {“C1″,”C1″,”G1″,”G1″,”A1″,”A1″,”G2″,”F1″,”F1″,”E1″,”E1″,”D1″,”D1″,”C2″,
“G1″,”G1″,”F1″,”F1″,”E1″,”E1″,”D2″,”G1″,”G1″,”F1″,”F1″,”E1″,”E1″,”D2″,
“C1″,”C1″,”G1″,”G1″,”A1″,”A1″,”G2″,”F1″,”F1″,”E1″,”E1″,”D1″,”D1″,”C2″,”END”};
dis is correct format... whn using dynamic initialization,,, dnt write *TTLSnote[],,
avoid [] symbols</description>
		<content:encoded><![CDATA[<p>char *TTLSnote = {“C1″,”C1″,”G1″,”G1″,”A1″,”A1″,”G2″,”F1″,”F1″,”E1″,”E1″,”D1″,”D1″,”C2″,<br />
“G1″,”G1″,”F1″,”F1″,”E1″,”E1″,”D2″,”G1″,”G1″,”F1″,”F1″,”E1″,”E1″,”D2″,<br />
“C1″,”C1″,”G1″,”G1″,”A1″,”A1″,”G2″,”F1″,”F1″,”E1″,”E1″,”D1″,”D1″,”C2″,”END”};<br />
dis is correct format&#8230; whn using dynamic initialization,,, dnt write *TTLSnote[],,<br />
avoid [] symbols</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ruhi sharma</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-3225</link>
		<dc:creator>ruhi sharma</dc:creator>
		<pubDate>Thu, 03 Feb 2011 06:47:42 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-3225</guid>
		<description>thanks....... 
n keep it up</description>
		<content:encoded><![CDATA[<p>thanks&#8230;&#8230;.<br />
n keep it up</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sadun</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-1950</link>
		<dc:creator>sadun</dc:creator>
		<pubDate>Sat, 20 Nov 2010 17:57:50 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-1950</guid>
		<description>Thanks a lot. I would recommend it.</description>
		<content:encoded><![CDATA[<p>Thanks a lot. I would recommend it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hugo I. Ramirez</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-1873</link>
		<dc:creator>Hugo I. Ramirez</dc:creator>
		<pubDate>Sun, 03 Oct 2010 04:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-1873</guid>
		<description>Thank you! This tutorial helped me a lot! I would recommend it a lot.</description>
		<content:encoded><![CDATA[<p>Thank you! This tutorial helped me a lot! I would recommend it a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vidhya</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-1823</link>
		<dc:creator>Vidhya</dc:creator>
		<pubDate>Sun, 29 Aug 2010 12:24:36 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-1823</guid>
		<description>Thanx......
Good work!</description>
		<content:encoded><![CDATA[<p>Thanx&#8230;&#8230;<br />
Good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-821</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 09 Feb 2010 10:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-821</guid>
		<description>@kenji  First of, I never used the Keil C51 compiler. The declaration looks fine (and also is good in VC2008 compiler.)

I found the following on keil compiler website:
&lt;blockquote&gt;This error message indicates that a segment named ?CO?MAIN, which is a COnstant in the MAIN segment, is 8000h bytes long and &lt;strong&gt;will not fit in the remaining CODE memory space&lt;/strong&gt;. This may be an indication that your program is growing too large or it may indicate that you need to increase the amount of ROM or RAM space available to your target hardware.&lt;/blockquote&gt;

The link to the page and the possible solution &lt;a href=&quot;http://www.keil.com/support/docs/1481.htm&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>@kenji  First of, I never used the Keil C51 compiler. The declaration looks fine (and also is good in VC2008 compiler.)</p>
<p>I found the following on keil compiler website:</p>
<blockquote><p>This error message indicates that a segment named ?CO?MAIN, which is a COnstant in the MAIN segment, is 8000h bytes long and <strong>will not fit in the remaining CODE memory space</strong>. This may be an indication that your program is growing too large or it may indicate that you need to increase the amount of ROM or RAM space available to your target hardware.</p></blockquote>
<p>The link to the page and the possible solution <a href="http://www.keil.com/support/docs/1481.htm" rel="nofollow">here</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kenji</title>
		<link>http://www.codingunit.com/c-tutorial-the-functions-malloc-and-free/comment-page-1#comment-818</link>
		<dc:creator>Kenji</dc:creator>
		<pubDate>Mon, 08 Feb 2010 16:50:57 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=216#comment-818</guid>
		<description>Hi guys, i know this may not be related but i urgently need help from your expertise, hoping to seek advices from you.

im trying to declare things like,

char *TTLSnote[] = {&quot;C1&quot;,&quot;C1&quot;,&quot;G1&quot;,&quot;G1&quot;,&quot;A1&quot;,&quot;A1&quot;,&quot;G2&quot;,&quot;F1&quot;,&quot;F1&quot;,&quot;E1&quot;,&quot;E1&quot;,&quot;D1&quot;,&quot;D1&quot;,&quot;C2&quot;,
&quot;G1&quot;,&quot;G1&quot;,&quot;F1&quot;,&quot;F1&quot;,&quot;E1&quot;,&quot;E1&quot;,&quot;D2&quot;,&quot;G1&quot;,&quot;G1&quot;,&quot;F1&quot;,&quot;F1&quot;,&quot;E1&quot;,&quot;E1&quot;,&quot;D2&quot;,
&quot;C1&quot;,&quot;C1&quot;,&quot;G1&quot;,&quot;G1&quot;,&quot;A1&quot;,&quot;A1&quot;,&quot;G2&quot;,&quot;F1&quot;,&quot;F1&quot;,&quot;E1&quot;,&quot;E1&quot;,&quot;D1&quot;,&quot;D1&quot;,&quot;C2&quot;,&quot;END&quot;};

and i got ERROR L107: ADDRESS SPACE OVERFLOW and &#039;DATA&#039;: SEGMENT TOO LARGE during compilation. Anyone may help?
btw, im using Keil C51 compiler. Many thank in advance.</description>
		<content:encoded><![CDATA[<p>Hi guys, i know this may not be related but i urgently need help from your expertise, hoping to seek advices from you.</p>
<p>im trying to declare things like,</p>
<p>char *TTLSnote[] = {&#8220;C1&#8243;,&#8221;C1&#8243;,&#8221;G1&#8243;,&#8221;G1&#8243;,&#8221;A1&#8243;,&#8221;A1&#8243;,&#8221;G2&#8243;,&#8221;F1&#8243;,&#8221;F1&#8243;,&#8221;E1&#8243;,&#8221;E1&#8243;,&#8221;D1&#8243;,&#8221;D1&#8243;,&#8221;C2&#8243;,<br />
&#8220;G1&#8243;,&#8221;G1&#8243;,&#8221;F1&#8243;,&#8221;F1&#8243;,&#8221;E1&#8243;,&#8221;E1&#8243;,&#8221;D2&#8243;,&#8221;G1&#8243;,&#8221;G1&#8243;,&#8221;F1&#8243;,&#8221;F1&#8243;,&#8221;E1&#8243;,&#8221;E1&#8243;,&#8221;D2&#8243;,<br />
&#8220;C1&#8243;,&#8221;C1&#8243;,&#8221;G1&#8243;,&#8221;G1&#8243;,&#8221;A1&#8243;,&#8221;A1&#8243;,&#8221;G2&#8243;,&#8221;F1&#8243;,&#8221;F1&#8243;,&#8221;E1&#8243;,&#8221;E1&#8243;,&#8221;D1&#8243;,&#8221;D1&#8243;,&#8221;C2&#8243;,&#8221;END&#8221;};</p>
<p>and i got ERROR L107: ADDRESS SPACE OVERFLOW and &#8216;DATA&#8217;: SEGMENT TOO LARGE during compilation. Anyone may help?<br />
btw, im using Keil C51 compiler. Many thank in advance.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

