<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title>help with pointers? c - Esoteric Chat</title>
	<link href="https://esoteric.chat/9601/help-with-pointers-c/" rel="alternate"/>
	<subtitle>c, error 73, memory management, pain in the ass, pointers, segfault</subtitle>	<id>https://esoteric.chat/feed/conversation/9601/</id>
	<updated>2025-02-26T22:13:07Z</updated>
	<generator>esoBB</generator>
	<entry>
		<title>marbles</title>
		<link href="https://esoteric.chat/post/42419/" rel="alternate"/>
		<id>https://esoteric.chat/post/42419/</id>
		<updated>2024-08-21T22:55:00Z</updated>
		<author>
			<name>marbles</name>
		</author>
		<content type="html"><![CDATA[<p>just use phppythonscript</p>]]></content>
	</entry>
	<entry>
		<title>Adolf Hitler</title>
		<link href="https://esoteric.chat/post/42388/" rel="alternate"/>
		<id>https://esoteric.chat/post/42388/</id>
		<updated>2024-08-20T18:52:47Z</updated>
		<author>
			<name>Adolf Hitler</name>
		</author>
		<content type="html"><![CDATA[<p>This can be simplified to:</p><pre>#include &lt;stdio.h&gt;

int main(void) {
  char message [] = &quot;The raids will never stop&quot;;
  printf(&quot;%s&#92;n&quot;, message);
  return 0;
}</pre><p>I don&#39;t know why you&#39;re returning 9 (returning 0 is the standard thing to do), you really don&#39;t need to print a string character by character. Did you get this code from somewhere else or did you write it yourself? In any case the %s formatting tag will print any valid (null-terminated) string so there is no need for whatever it is that was going on before.</p><p>If you did want to loop through a string character by character, you would just index it like an array. E.g:</p><pre>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main() {
  char message[] = &quot;The raids will never stop&quot;;
  for (int i = 0; i &lt; strlen(message); i++) {
    printf(&quot;%c&quot;, message[i]);
  }
  printf(&quot;&#92;n&quot;);
  return 0;
}</pre><p>Ultimately it isn&#39;t that complicated, and it&#39;s best to not make it complicated needlessly. Maybe a language like python would be more your speed, but C isn&#39;t difficult when you know what you&#39;re doing.</p><p>One last thing, you generally use pointers when you want to be able to dynamically allocate and de-allocate memory (variables). I.E. writing efficient programs that only use memory when it&#39;s needed and free it up immediately once they&#39;re done with it.</p>]]></content>
	</entry>
	<entry>
		<title>Speciality</title>
		<link href="https://esoteric.chat/post/42374/" rel="alternate"/>
		<id>https://esoteric.chat/post/42374/</id>
		<updated>2024-08-18T21:57:21Z</updated>
		<author>
			<name>Speciality</name>
		</author>
		<content type="html"><![CDATA[<p>Pointers are pretty self-explanatory. &quot;When to use pointers&quot; should be <b>whenever you can</b>, in my opinion.</p>]]></content>
	</entry>
	<entry>
		<title>anker</title>
		<link href="https://esoteric.chat/post/42373/" rel="alternate"/>
		<id>https://esoteric.chat/post/42373/</id>
		<updated>2024-08-18T19:19:45Z</updated>
		<author>
			<name>anker</name>
		</author>
		<content type="html"><![CDATA[<p>idk how to read code</p>]]></content>
	</entry>
	<entry>
		<title>void *</title>
		<link href="https://esoteric.chat/post/42362/" rel="alternate"/>
		<id>https://esoteric.chat/post/42362/</id>
		<updated>2024-08-17T19:36:46Z</updated>
		<author>
			<name>void *</name>
		</author>
		<content type="html"><![CDATA[<p>here&#39;s what I got so far:</p><p>#include &lt;stdio.h&gt;</p><p>int main(void) {<br/> char message [] = &quot;The raids will never stop&quot;;<br/> char * message_POINTER = message;</p><p> while(1) {<br/>  char characTer = *(message_POINTER++);<br/>  if(characTer == &#39;&#92;0&#39;) break;<br/>  else {<br/>   printf(&quot;%c&quot;, characTer);<br/>  }<br/> }<br/> <br/> printf(&quot;&#92;n&quot;);<br/> return 9;<br/>}</p>]]></content>
	</entry>
	<entry>
		<title>void *</title>
		<link href="https://esoteric.chat/post/42349/" rel="alternate"/>
		<id>https://esoteric.chat/post/42349/</id>
		<updated>2024-08-16T06:28:11Z</updated>
		<author>
			<name>void *</name>
		</author>
		<content type="html"><![CDATA[<p>Need guides on learning how pointers work and when I should be using them… is the main reason why im not learning c.</p>]]></content>
	</entry>
</feed>
