<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://www.linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sat May 25, 2013 3:59 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sat May 25, 2013 3:59 am</pubDate>
  <lastBuildDate>Sat May 25, 2013 3:59 am</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://www.linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>RE: C functions and libraries</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=21575#21575</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=299'&gt;TonyLB&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Apr 19, 2006 6:07 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Thanks, yes.&lt;br /&gt;
In fact, in my original code I'd uses a char array which was passed to insert, and the later version user a char* instead, which seems to be the problem at least in part since there was no room for the inserted characters.&lt;br /&gt;
&lt;br /&gt;
Tony</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=21575#21575</comments>
                                        <author>TonyLB</author>
                                        <pubDate>Wed Apr 19, 2006 6:07 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=21575#21575</guid>
                                      </item>
                                      <item>
                                        <title>RE: C functions and libraries</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=21498#21498</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=162'&gt;Nigel&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Tue Apr 18, 2006 9:33 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      OK, I think the answer lies in how you are calling the routine. Are you doing something like this...&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;char string1&amp;#91;1024&amp;#93;;&lt;br /&gt;
&amp;nbsp; char string2&amp;#91;1024&amp;#93;;&lt;br /&gt;
&amp;nbsp; char *str1;&lt;br /&gt;
&amp;nbsp; char *str2;&lt;br /&gt;
&amp;nbsp; str1 = &amp;quot;I believe it&amp;quot;;&lt;br /&gt;
&amp;nbsp; str2 = &amp;quot;DON'T &amp;quot;;&lt;br /&gt;
&amp;nbsp; insert &amp;#40;str2, str1, 2&amp;#41;;&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
If so, the segfault is because you have changed the pointer str1 to point to the literal &quot;I believe it&quot; instead of the character array string1. It is not legal to write to a string literal.&lt;br /&gt;
The calling sequence should be something like this :&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;char string1&amp;#91;1024&amp;#93;;&lt;br /&gt;
&amp;nbsp; char string2&amp;#91;1024&amp;#93;;&lt;br /&gt;
&amp;nbsp; char *str1;&lt;br /&gt;
&amp;nbsp; char *str2;&lt;br /&gt;
&amp;nbsp; strcpy &amp;#40;str1,&amp;quot;I believe it&amp;quot;&amp;#41;;&lt;br /&gt;
&amp;nbsp; strcpy &amp;#40;str2,&amp;quot;DON'T &amp;quot;&amp;#41;;&lt;br /&gt;
&amp;nbsp; insert &amp;#40;str2, str1, 2&amp;#41;;&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=21498#21498</comments>
                                        <author>Nigel</author>
                                        <pubDate>Tue Apr 18, 2006 9:33 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=21498#21498</guid>
                                      </item>
                                      <item>
                                        <title>C functions and libraries</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=21474#21474</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=299'&gt;TonyLB&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Apr 17, 2006 5:19 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      I'm just learning C as another language, and I'm trying to build some utilities into a library.  I have this (crude I know) function:&lt;br /&gt;
void insert(char* insrt, char* source, int place){&lt;br /&gt;
	char temp[strlen(insrt)+strlen(source)+1];&lt;br /&gt;
	strncpy(temp, source, place);&lt;br /&gt;
	temp[place]='\0';&lt;br /&gt;
	strcat(temp, insrt);&lt;br /&gt;
	strcat(temp, source+place);&lt;br /&gt;
	strcpy(source, temp);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
In a simple file, it all works, but in a static library, when I call it I get a segnmentation fault.  The villain is the final strcpy.&lt;br /&gt;
&lt;br /&gt;
I tried returning temp instead and that doesn't work either, I don't get quite the string that exists in the function (and the compiler warns about returning a local variable).&lt;br /&gt;
&lt;br /&gt;
I know there's a solution, I just have no idea what it is.  Any help would be great.&lt;br /&gt;
&lt;br /&gt;
Tony</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=21474#21474</comments>
                                        <author>TonyLB</author>
                                        <pubDate>Mon Apr 17, 2006 5:19 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=21474#21474</guid>
                                      </item></channel></rss>