1 line
No EOL
55 KiB
XML
1 line
No EOL
55 KiB
XML
<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><category term="cprogramming" label="r/cprogramming"/><updated>2023-01-28T12:51:07+00:00</updated><icon>https://www.redditstatic.com/icon.png/</icon><id>/r/cprogramming.rss</id><link rel="self" href="https://www.reddit.com/r/cprogramming.rss" type="application/atom+xml" /><link rel="alternate" href="https://www.reddit.com/r/cprogramming" type="text/html" /><subtitle>A Subreddit dedicated to the C programming language. Everything related to C is welcome here.</subtitle><title>Old School C Programming Subreddit</title><entry><author><name>/u/DancingPotato30</name><uri>https://www.reddit.com/user/DancingPotato30</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I&#39;ve been awake for multiple hours trying to do this. I don&#39;t want to know if my logic is wrong or if I am doing it the wrong way because I want to do it myself, I don&#39;t know how to fix the errors I keep getting. I might have misunderstood how functions work. </p> <p>My code:</p> <p>#include &lt;stdio.h&gt;<br/> #include &lt;cs50.h&gt;<br/> #include &lt;string.h&gt;<br/> #include &lt;ctype.h&gt;<br/> int only_digits(int result);<br/> int main(int argc, string argv[])<br/> {<br/> int check = 1;<br/> int answer = only_digits(check);<br/> printf(&quot;%i&quot;, check);<br/> if (check == 1)<br/> {<br/> printf(&quot;Only digits allowed!\n&quot;);<br/> return 1;<br/> }<br/> if(argv[2] != NULL)<br/> {<br/> printf(&quot;Usage: ./week2 Key\n&quot;);<br/> return 1;<br/> }<br/> printf(&quot;Success&quot;);<br/> printf(&quot;\n&quot;);<br/> }<br/> int only_digits(int result)<br/> {<br/> for(int i = 1; i &lt; strlen(argv); i++)<br/> {<br/> if (isdigit(argv[i]))<br/> {<br/> result = 0;<br/> }<br/> else<br/> {<br/> result = 1;<br/> }<br/> }<br/> return result;<br/> } </p> <p>I know, long and not efficient but I am still learning...</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/DancingPotato30"> /u/DancingPotato30 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10n8uuo/trying_to_make_a_cipher_but_my_function_keeps/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10n8uuo/trying_to_make_a_cipher_but_my_function_keeps/">[comments]</a></span></content><id>t3_10n8uuo</id><link href="https://www.reddit.com/r/cprogramming/comments/10n8uuo/trying_to_make_a_cipher_but_my_function_keeps/" /><updated>2023-01-28T07:05:47+00:00</updated><published>2023-01-28T07:05:47+00:00</published><title>Trying to make a cipher but my function keeps breaking</title></entry><entry><author><name>/u/fk0190</name><uri>https://www.reddit.com/user/fk0190</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hello, I need help for 3D rotations translation I need 3 functions where one is for x rotation, one y and one z! There is a 3x3 array and angle is in deg. Can someone explain how I should proceed? Thankss</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/fk0190"> /u/fk0190 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10n8k4k/3d_rotation_in_c/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10n8k4k/3d_rotation_in_c/">[comments]</a></span></content><id>t3_10n8k4k</id><link href="https://www.reddit.com/r/cprogramming/comments/10n8k4k/3d_rotation_in_c/" /><updated>2023-01-28T06:47:50+00:00</updated><published>2023-01-28T06:47:50+00:00</published><title>3D rotation in C</title></entry><entry><author><name>/u/LazyWorkaholic1612</name><uri>https://www.reddit.com/user/LazyWorkaholic1612</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>so we had this programming project in c. and I have no experience or any idea on what to do.</p> <p>we are supposed to convert this following.</p> <p>binary to decimal</p> <p>binary to octal</p> <p>binary to hexadecimal</p> <p>decimal to binary</p> <p>octal to binary</p> <p>hexadecimal to binary</p> <p>&#x200B;</p> <p>&#x200B;</p> <p>help, I am literally crying. we are supposed to do this within one program. and use b, d, o, h as suffixes to identify the input.</p> <p>&#x200B;</p> <p>how am I supposed to start</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/LazyWorkaholic1612"> /u/LazyWorkaholic1612 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10n86nx/help/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10n86nx/help/">[comments]</a></span></content><id>t3_10n86nx</id><link href="https://www.reddit.com/r/cprogramming/comments/10n86nx/help/" /><updated>2023-01-28T06:25:30+00:00</updated><published>2023-01-28T06:25:30+00:00</published><title>help</title></entry><entry><author><name>/u/Sqwishboi</name><uri>https://www.reddit.com/user/Sqwishboi</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hey<br/> So recently I&#39;ve encountered this weird output on c.<br/> I&#39;ve tried slowly debugging it to track the &#39;size&#39; variable (including digging in to the disassembler and still don&#39;t understand why this happens).<br/> I&#39;ve also (don&#39;t hate me) tried to get chatGPT to explain, but it has failed to give a clear answer.<br/> Shouldn&#39;t the first size be 5?</p> <p>Maybe one of you gents can assist. It a really simple code.<br/> <strong>Code:</strong></p> <p>#include &lt;stdio.h&gt;<br/> <em>int doSomething(int c)</em><br/> {<br/> return c;<br/> }<br/> <em>int main()</em><br/> {<br/> int size = 5;<br/> printf(&quot;size: %d , func: %d , size: %d , func: %d , size: %d&quot;<br/> ,size,doSomething(size--),size,doSomething(size--),size);<br/> return 0;<br/> } </p> <p><strong>Output:</strong><br/> size: 3 , func: 4 , size: 3 , func: 5 , size: 3<br/> Process finished with exit code 0.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Sqwishboi"> /u/Sqwishboi </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10mq4v1/weird_program_output/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10mq4v1/weird_program_output/">[comments]</a></span></content><id>t3_10mq4v1</id><link href="https://www.reddit.com/r/cprogramming/comments/10mq4v1/weird_program_output/" /><updated>2023-01-27T17:11:23+00:00</updated><published>2023-01-27T17:11:23+00:00</published><title>Weird program output</title></entry><entry><author><name>/u/thelazycheetuh2</name><uri>https://www.reddit.com/user/thelazycheetuh2</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I am trying to figure out how to solve the kepler problem by essentially forming an ellipse using kinematic equations. I assume x and y would affect eachother by trying to keep &quot;r&quot; constant, but I can&#39;t figure out how to do so. If someone can help me out, I would very much appreciate it. Here is my code:</p> <p>#include &lt;stdio.h&gt;</p> <p>#include &lt;math.h&gt;</p> <p>int main()</p> <p>{</p> <p>double x,y,vx,vy,ax,ay,M,g,rx,ry,rr,r,dt;</p> <p>int i,N;</p> <p>FILE * fileout;</p> <p>g=9.8;</p> <p>M=1;</p> <p>fileout=fopen(&quot;Kepler.csv&quot;,&quot;w&quot;);</p> <p>printf(&quot;\nEnter Initial Position, x:\n&quot;);</p> <p>scanf(&quot;%lf&quot;, &amp;x);</p> <p>printf(&quot;\nEnter Initial Position, y:\n&quot;);</p> <p>scanf(&quot;%lf&quot;, &amp;y);</p> <p>printf(&quot;\nEnter Initial Velocity in x direction, vx:\n&quot;);</p> <p>scanf(&quot;%lf&quot;, &amp;vx);</p> <p>printf(&quot;\nEnter Initial Velocity in x direction, vy:\n&quot;);</p> <p>scanf(&quot;%lf&quot;, &amp;vy);</p> <p>printf(&quot;\nEnter dt:\n&quot;);</p> <p>scanf(&quot;%lf&quot;, &amp;dt);</p> <p>printf(&quot;\nEnter N:\n&quot;);</p> <p>scanf(&quot;%i&quot;, &amp;N);</p> <p>rx=pow(x,2);</p> <p>ry=pow(y,2);</p> <p>rr=rx+ry;</p> <p>r=pow(rr,0.5);</p> <p>ax=-g*M*x/pow(r,3);</p> <p>ay=-g*M*y/pow(r,3);</p> <p>for (i=1; i&lt;N+1; i=i+1)</p> <p>{</p> <p>vy=vy-ay*dt;</p> <p>vx=vy-ax*dt;</p> <p>x=x+vx*dt;</p> <p>y=y+vy*dt;</p> <p>ax=ax+x*dt;</p> <p>ay=ay+y*dt;</p> <p>fprintf(fileout,&quot;\n%lf; %lf&quot;, x, y);</p> <p>}</p> <p>fclose(fileout);</p> <p>}</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/thelazycheetuh2"> /u/thelazycheetuh2 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10n22f7/form_an_ellipse_with_c_code/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10n22f7/form_an_ellipse_with_c_code/">[comments]</a></span></content><id>t3_10n22f7</id><link href="https://www.reddit.com/r/cprogramming/comments/10n22f7/form_an_ellipse_with_c_code/" /><updated>2023-01-28T01:14:41+00:00</updated><published>2023-01-28T01:14:41+00:00</published><title>Form an ellipse with c code</title></entry><entry><author><name>/u/Cabernetcabe</name><uri>https://www.reddit.com/user/Cabernetcabe</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I’ve tried gcc {filename}.c -o {filename}.exe but this didn’t work I am a beginner so pls help me</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Cabernetcabe"> /u/Cabernetcabe </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10mxj4l/how_can_i_compile_and_execute_a_c_program_in/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10mxj4l/how_can_i_compile_and_execute_a_c_program_in/">[comments]</a></span></content><id>t3_10mxj4l</id><link href="https://www.reddit.com/r/cprogramming/comments/10mxj4l/how_can_i_compile_and_execute_a_c_program_in/" /><updated>2023-01-27T22:05:23+00:00</updated><published>2023-01-27T22:05:23+00:00</published><title>How can I compile and execute a c program in ubuntu Linux?</title></entry><entry><author><name>/u/OkDance22</name><uri>https://www.reddit.com/user/OkDance22</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html">&#32; submitted by &#32; <a href="https://www.reddit.com/user/OkDance22"> /u/OkDance22 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10m6nxo/best_data_structure_books/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10m6nxo/best_data_structure_books/">[comments]</a></span></content><id>t3_10m6nxo</id><link href="https://www.reddit.com/r/cprogramming/comments/10m6nxo/best_data_structure_books/" /><updated>2023-01-27T00:02:33+00:00</updated><published>2023-01-27T00:02:33+00:00</published><title>Best data structure books?</title></entry><entry><author><name>/u/Common-Astronaut-465</name><uri>https://www.reddit.com/user/Common-Astronaut-465</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>My code is printing all the edges for both tree traversals algorithms. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define SIZE 40 struct node { char data; struct node *next; }; struct node *top = NULL; void push(char data) { struct node *newNode = (struct node *)malloc(sizeof(struct node)); newNode-&gt;data = data; newNode-&gt;next = top; top = newNode; } char pop() { char data; struct node *temp; if (top == NULL) { printf(&quot;Stack is empty &quot;); } else { temp = top; data = temp-&gt;data; top = top-&gt;next; temp-&gt;next = NULL; free(temp); } return data; } int isEmpty() { if (top == NULL) return 1; else return 0; } // create a queue Q using linked list struct node1 { char data; struct node1 *next; }; struct node1 *front = NULL; struct node1 *rear = NULL; void enqueue(char data) { struct node1 *newNode = (struct node1 *)malloc(sizeof(struct node1)); newNode-&gt;data = data; newNode-&gt;next = NULL; if (front == NULL) { front = rear = newNode; } else { rear-&gt;next = newNode; rear = newNode; } } char dequeue() { char data; struct node1 *temp; if (front == NULL) { printf(&quot;Queue is empty &quot;); } else { temp = front; data = temp-&gt;data; front = front-&gt;next; temp-&gt;next = NULL; free(temp); } return data; } int isEmpty1() { if (front == NULL) return 1; else return 0; } // create a graph using adjacency list struct node2 { char data; struct node2 *next; }; struct node2 *head[SIZE] = {NULL}; void insert(char data) { struct node2 *newNode = (struct node2 *)malloc(sizeof(struct node2)); newNode-&gt;data = data; newNode-&gt;next = NULL; if (head[data - &#39;A&#39;] == NULL) { head[data - &#39;A&#39;] = newNode; } else { struct node2 *temp = head[data - &#39;A&#39;]; while (temp-&gt;next != NULL) { temp = temp-&gt;next; } temp-&gt;next = newNode; } } void insertEdge(char data1, char data2) { struct node2 *newNode = (struct node2 *)malloc(sizeof(struct node2)); newNode-&gt;data = data2; newNode-&gt;next = NULL; if (head[data1 - &#39;A&#39;] == NULL) { head[data1 - &#39;A&#39;] = newNode; } else { struct node2 *temp = head[data1 - &#39;A&#39;]; while (temp-&gt;next != NULL) { temp = temp-&gt;next; } temp-&gt;next = newNode; } } void display() { int i; printf(&quot;\n***** Graph *****&quot;); printf(&quot;\nVertices: &quot;); for (i = 0; i &lt; SIZE; i++) { if (head[i] != NULL) { printf(&quot;%c &quot;, head[i]-&gt;data); } } printf(&quot;\nEdges: &quot;); for (i = 0; i &lt; SIZE; i++) { if (head[i] != NULL) { struct node2 *temp = head[i]; while (temp != NULL) { printf(&quot;(%c,%c) &quot;, head[i]-&gt;data, temp-&gt;data); temp = temp-&gt;next; } } } printf(&quot;\n&quot;); } // DFS algorithm void DFS(char data) { int i; int visited[SIZE] = {0}; push(data); visited[data - &#39;A&#39;] = 1; printf(&quot;\n***** DFS Tree *****&quot;); printf(&quot;\nVertices: &quot;); while (!isEmpty()) { char temp = pop(); printf(&quot;%c &quot;, temp); struct node2 *temp1 = head[temp - &#39;A&#39;]; while (temp1 != NULL) { if (visited[temp1-&gt;data - &#39;A&#39;] == 0) { push(temp1-&gt;data); visited[temp1-&gt;data - &#39;A&#39;] = 1; } temp1 = temp1-&gt;next; } } printf(&quot;\nEdges: &quot;); for (i = 0; i &lt; SIZE; i++) { if (head[i] != NULL) { struct node2 *temp = head[i]; while (temp != NULL) { if (visited[temp-&gt;data - &#39;A&#39;] == 1) // print only visited edges { printf(&quot;(%c,%c) &quot;, head[i]-&gt;data, temp-&gt;data); } temp = temp-&gt;next; } } } printf(&quot;\n&quot;); } // BFS void BFS(char data) { int i; int visited[SIZE] = {0}; enqueue(data); visited[data - &#39;A&#39;] = 1; printf(&quot;\n***** BFS Tree *****&quot;); printf(&quot;\nVertices: &quot;); while (!isEmpty1()) { char temp = dequeue(); printf(&quot;%c &quot;, temp); struct node2 *temp1 = head[temp - &#39;A&#39;]; while (temp1 != NULL) { if (visited[temp1-&gt;data - &#39;A&#39;] == 0) { enqueue(temp1-&gt;data); visited[temp1-&gt;data - &#39;A&#39;] = 1; } temp1 = temp1-&gt;next; } } printf(&quot;\nEdges: &quot;); for (i = 0; i &lt; SIZE; i++) { if (head[i] != NULL) { struct node2 *temp = head[i]; while (temp != NULL) { //print only those edges which are present in BFS tree if (visited[temp-&gt;data - &#39;A&#39;] == 1) { printf(&quot;(%c,%c) &quot;, head[i]-&gt;data, temp-&gt;data); } temp = temp-&gt;next; } } } printf(&quot;\n&quot;); } // main function int main() { int i, e, n; char data1, data2, start; /*for (i = 0; i &lt; SIZE; i++) { insert(i + &#39;A&#39;); }*/ printf(&quot;Enter the number of vertices: &quot;); scanf(&quot;%d&quot;, &amp;n); printf(&quot;Enter the vertices: &quot;); for (i = 0; i &lt; n; i++) { scanf(&quot; %c&quot;, &amp;data1); insert(data1); } printf(&quot;Enter the number of edges: &quot;); scanf(&quot;%d&quot;, &amp;e); printf(&quot;Enter the edges: &quot;); for (i = 0; i &lt; e; i++) { scanf(&quot; %c %c&quot;, &amp;data1, &amp;data2); insertEdge(data1, data2); } display(); printf(&quot;Enter the starting vertex: &quot;); scanf(&quot; %c&quot;, &amp;start); DFS(start); BFS(start); return 0; } </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Common-Astronaut-465"> /u/Common-Astronaut-465 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10mg37m/tree_traversal/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10mg37m/tree_traversal/">[comments]</a></span></content><id>t3_10mg37m</id><link href="https://www.reddit.com/r/cprogramming/comments/10mg37m/tree_traversal/" /><updated>2023-01-27T08:34:54+00:00</updated><published>2023-01-27T08:34:54+00:00</published><title>Tree traversal</title></entry><entry><author><name>/u/randint4923</name><uri>https://www.reddit.com/user/randint4923</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>```c</p> <h1>include &lt;stdio.h&gt;</h1> <p>int main(void) { int i = 0; int j = 0;</p> <pre><code> printf(&quot;%d &quot;, i++); //i = 0 printf(&quot;%d&quot;, i); //i = 1 printf(&quot;\n&quot;); printf(&quot;%d &quot;, ++j); //j = 1 printf(&quot;%d&quot;, j); //j = 1 for(int i = 0 ; i &lt; 5; ++i) printf(&quot;%d\n&quot;, i); // prints 0 1 2 3 4 // and not 1 2 3 4 </code></pre> <p>} ``` Hello! I would like to ask for help. Given how the increment operator works. I do not understand why the for loops uses the value 0. Could someone please explain that part for me. Thank you.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/randint4923"> /u/randint4923 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10mf6ix/questions_increment_operator/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10mf6ix/questions_increment_operator/">[comments]</a></span></content><id>t3_10mf6ix</id><link href="https://www.reddit.com/r/cprogramming/comments/10mf6ix/questions_increment_operator/" /><updated>2023-01-27T07:32:17+00:00</updated><published>2023-01-27T07:32:17+00:00</published><title>Questions: Increment operator</title></entry><entry><author><name>/u/Ok-Necessary-5859</name><uri>https://www.reddit.com/user/Ok-Necessary-5859</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Thank you to anyone reading this , i have a problem with a part of my code , im learning to do functions, and functions enter,get_random work fine.</p> <p>Now i want to add function addsum, but for some reason when i run the code with it, the debugger stops me when the loop of column finishes and the loop with row should start .</p> <p>Could anyone tell me what i am doing wrong? i only know the bare essentials of pointers, maybe that is the solution to my problems? thanks in advance.</p> <p>This is the message from debugger</p> <p>passing argument 4 of ‘addsum’ makes pointer from integer without a cast [-Wint-conversion]</p> <pre><code>#include&lt;math.h&gt; #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; // libraries added from example #include&lt;time.h&gt; //(*) For a square matrix calculate the sum of elements under the main diagonal excluding it. define A -10 define B 10 int main(){ void enter(int *x,int *y); int get_random(int lbound,int ubound); int addsum(int ro, int co, int s, int arr[ro][co]); int r; int c; int row,col,sum=0; enter(&amp;r,&amp;c); srand48(time(NULL)); //Call srand48 with current time reported by time casted to a long integer. // srand48 is used to reinitialize the most recent 48-bit value in this storage int array[r][c]; // we decided its gonna be r rows and c columns for (row=0;row&lt;r;++row) // we cycle numeration of rows of matrix { for(col=0;col&lt;c;col++) // we cycle numeration of columns of matrix { array[row][col]=get_random(B,A);// filling array with random numbers printf(&quot;%d &quot;,array[row][col]); addsum(row, col, sum, array[row][col]); } printf(&quot;\n&quot;); // this is to break line after row 1,2 col 3, so it looks nicer } printf(&quot;\n&quot;); printf(&quot;sum of array: %d\n&quot;, sum); return 0; } void enter(int *x,int *y){ // we have to use pointers if we want more then one return from a function printf(&quot;How man rows in array? &quot;); scanf(&quot;%d&quot;, x); // we use x instead of &amp;x because we need the adress of the number not the value printf(&quot;How man columns in array? &quot;); scanf(&quot;%d&quot;, y); // we use y instead of &amp;y because we need the adress of the number not the value } int get_random(int lbound,int ubound) { return rand()%(ubound-lbound+1)+lbound; // function for generating random numbers } int addsum(int ro, int co, int s, int arr[ro][co]) { if (ro&gt;co){ //since we want the sum numbers below the diagonal row&gt;col must be true s=s+arr[ro][co];// if row&gt;col than we add the number to our sum return s; } } </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Ok-Necessary-5859"> /u/Ok-Necessary-5859 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10m4nb7/functions_matrices_arrays_problems/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10m4nb7/functions_matrices_arrays_problems/">[comments]</a></span></content><id>t3_10m4nb7</id><link href="https://www.reddit.com/r/cprogramming/comments/10m4nb7/functions_matrices_arrays_problems/" /><updated>2023-01-26T22:33:34+00:00</updated><published>2023-01-26T22:33:34+00:00</published><title>Functions, matrices, arrays, problems.</title></entry><entry><author><name>/u/Yudiaramos</name><uri>https://www.reddit.com/user/Yudiaramos</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I&#39;m getting back to C programming and decided to try to write a code that reads a file with multiple ints inside and counts how many of them have values that range in a certain amount. But for some reason the code reads the last line twice and counts 1 more int than its supposed to. How can I fix that? I&#39;ve tried changing the while to</p> <pre><code>fgets(buffer, MAX_LINELENGTH, fpointer) </code></pre> <p>But I didn&#39;t help.</p> <p>This is what I&#39;m working with right now:</p> <pre><code>void ocorrencias(int col){ char str[60]; float grade1, grade2, grade3, check; int int1 = 0; int int2 = 0; int int3 = 0; int int4 = 0; FILE *fpointer; fpointer = fopen(&quot;grades.csv&quot;,&quot;r&quot;); if(fpointer == NULL){ printf(&quot;ERROR!&quot;); } // while(fgets(buffer, 100, fpointer) != NULL){ while(!feof(fpointer)){ if(col == 1){ fscanf(fpointer,&quot;%f, %f, %f, %f&quot;, &amp;grade1, &amp;grade2, &amp;grade3, &amp;check); //compare(grade1, int1, int2, int3, int4); if(grade1 &gt;= 0 &amp;&amp; grade1 &lt;= 2.99){ int1++; } else if(grade1 &gt;= 3.00 &amp;&amp; grade1 &lt;= 4.99){ int2++; } else if(grade1 &gt;= 5.00 &amp;&amp; grade1 &lt;= 7.99){ int3++; } else if(grade1 &gt;= 8.00 &amp;&amp; grade1 &lt;= 10.00){ int4++; } } if(col == 2){ fscanf(fpointer,&quot;%f, %f, %f, %f&quot;, &amp;grade1, &amp;grade2, &amp;grade3, &amp;check); if(grade2 &gt;= 0 &amp;&amp; grade2 &lt;= 2.99){ int1++; } else if(grade2 &gt;= 3.00 &amp;&amp; grade2 &lt;= 4.99){ int2++; } else if(grade2 &gt;= 5.00 &amp;&amp; grade2 &lt;= 7.99){ int3++; } else if(grade2 &gt;= 8.00 &amp;&amp; grade2 &lt;= 10.00){ int4++; } } if(col == 3){ fscanf(fpointer,&quot;%f, %f, %f, %f&quot;, &amp;grade1, &amp;grade2, &amp;grade3, &amp;check); if(grade3 &gt;= 0 &amp;&amp; grade3 &lt;= 2.99){ int1++; } else if(grade3 &gt;= 3.00 &amp;&amp; grade3 &lt;= 4.99){ int2++; } else if(grade3 &gt;= 5.00 &amp;&amp; grade3 &lt;= 7.99){ int3++; } else if(grade3 &gt;= 8.00 &amp;&amp; grade3 &lt;= 10.00){ int4++; } } if(col == 4){ fscanf(fpointer,&quot;%f, %f, %f, %f&quot;, &amp;grade1, &amp;grade2, &amp;grade3, &amp;check); } } print(int1, int2, int3, int4); fclose(fpointer); } </code></pre> <p>Only did the ifs for column 1, for testing.</p> <p>and the txt file:</p> <pre><code>2.50,3.00,3.00,0 2.50,2.50,3.00,0 3.50,4.00,5.00,0 7.50,7.00,7.50,0 3.00,5.00,5.00,0 7.50,7.50,7.50,0 6.00,6.00,5.50,0 3.00,2.50,3.00,0 8.00,9.00,9.50,0 7.00,7.50,7.50,0 </code></pre> <p>the output I&#39;m getting is:</p> <pre><code>2 3 5 1 </code></pre> <p>(occurrence 1, 2, 3 and 4 respectively).</p> <p>but I&#39;m supposed to get:</p> <pre><code>2 3 4 1 </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Yudiaramos"> /u/Yudiaramos </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10lvylg/last_line_of_file_read_twice_in_c/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10lvylg/last_line_of_file_read_twice_in_c/">[comments]</a></span></content><id>t3_10lvylg</id><link href="https://www.reddit.com/r/cprogramming/comments/10lvylg/last_line_of_file_read_twice_in_c/" /><updated>2023-01-26T16:33:28+00:00</updated><published>2023-01-26T16:33:28+00:00</published><title>Last line of file read twice in C</title></entry><entry><author><name>/u/trekgirl47</name><uri>https://www.reddit.com/user/trekgirl47</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hi I&#39;m trying to make a program that creates a linked list. I&#39;m trying to list a periodic element, the atomic symbol and the weight. It would be for ten elements, I want each node to output :</p> <p>Hydrogen, H, 1.008 : ...</p> <p>I know I can use a void pointer or a union, I started writing a program using void pointer. All I know how to do is create a separate node for each data type, is there a way to consolidate the three data types into one node?</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/trekgirl47"> /u/trekgirl47 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10lrwff/creating_a_linked_list_with_2_strings_and_a_float/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10lrwff/creating_a_linked_list_with_2_strings_and_a_float/">[comments]</a></span></content><id>t3_10lrwff</id><link href="https://www.reddit.com/r/cprogramming/comments/10lrwff/creating_a_linked_list_with_2_strings_and_a_float/" /><updated>2023-01-26T13:33:34+00:00</updated><published>2023-01-26T13:33:34+00:00</published><title>creating a linked list with 2 strings and a float in each node?</title></entry><entry><author><name>/u/Prestigious_Carob745</name><uri>https://www.reddit.com/user/Prestigious_Carob745</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hey all, I’m not sure if this is the right place to post this but I took a week or two off from coding and came back to find the linker giving me huge problems</p> <p>I use the Microsoft compiler. When I compile, it gives linker error 1104 - cannot open the (name of output executable). Sometimes. </p> <p>When I can get it to compile the binary is eight or nine times larger than it was before I took the break. I haven’t changed the code. The only thing I’ve changed on the system was I created another folder for a code repository, created an empty c file (with WinMain) and wrote a quick batch file to compile it. But that’s when I noticed it wasn’t linking properly and when it did the binaries were huge and I still couldn’t get release versions of former projects to compile. </p> <p>I’m pulling my hair out here. I REALLY don’t want to just uninstall the entire compiler, but I have no idea what happened. Has anyone else experienced the same problem?</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Prestigious_Carob745"> /u/Prestigious_Carob745 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10lkrc7/bizarre_explosion_of_binary_size/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10lkrc7/bizarre_explosion_of_binary_size/">[comments]</a></span></content><id>t3_10lkrc7</id><link href="https://www.reddit.com/r/cprogramming/comments/10lkrc7/bizarre_explosion_of_binary_size/" /><updated>2023-01-26T05:45:02+00:00</updated><published>2023-01-26T05:45:02+00:00</published><title>Bizarre explosion of binary size</title></entry><entry><author><name>/u/scorpiusxx</name><uri>https://www.reddit.com/user/scorpiusxx</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>hey, i have a small stupid question about this script</p> <p><sup>#include &lt;stdio.h&gt;</sup><br/> <sup>#include &lt;sys/types.h&gt;</sup><br/> <sup>#include &lt;unistd.h&gt;</sup><br/> <sup>#include &lt;sys/wait.h&gt;</sup><br/> <sup>#include &lt;stdlib.h&gt;</sup><br/> <sup>int main (</sup>)<br/> <sup>{</sup><br/> <sup>int j = getpid(;</sup>)<br/> <sup>printf( &quot;itsme %d\</sup>n&quot;,j;))<br/> <sup>for (int k=0; k&lt;2; k++</sup>)<br/> <sup>{</sup><br/> <sup>int i = fork(;</sup>)<br/> <sup>j = getpid(;</sup>)<br/> <sup>printf( &quot;itsme %d\</sup>n&quot;,j;))<br/> <sup>}</sup><br/> <sup>exit(EXIT\</sup>SUCCESS;))<br/> <sup>}</sup></p> <p>i&#39;m just learning this type of stuff, and i&#39;m not sure how many times function fork() will be used in this code. Will it be only 2 times, because of the loop size? Or is it gonna clone itself somehow?</p> <p>also after running this small program, printf function is executed 7 times. 3 of this printf have the same pid number, then 2 of them also have the same numbers, and 2 of them have unique number. Can someone tell me why? thanks</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/scorpiusxx"> /u/scorpiusxx </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10ls5cs/question_about_script/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10ls5cs/question_about_script/">[comments]</a></span></content><id>t3_10ls5cs</id><link href="https://www.reddit.com/r/cprogramming/comments/10ls5cs/question_about_script/" /><updated>2023-01-26T13:46:10+00:00</updated><published>2023-01-26T13:46:10+00:00</published><title>question about script</title></entry><entry><author><name>/u/Ok-Necessary-5859</name><uri>https://www.reddit.com/user/Ok-Necessary-5859</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I have a problem with some code I&#39;m trying to write and neither debugger nor google can explain to what I&#39;m doing wrong.</p> <p>I want to write the size of the array myself and then to input all the digits of the array myself. What am doing wrong? Also debugger asked me to use %ls instead of %d, could anyone explain to me when i should use what?</p> <pre><code>#include &lt;stdio.h&gt; int main() { int n; int arr[n]; printf(&quot;enter size of array&quot;); scanf(&quot;%ls&quot;, &amp;n); for (int i = 0; i &lt; n; i++) { scanf(&quot;%ls&quot;, &amp;arr[i]); printf(&quot;%ls\n&quot;, &amp;arr[i]); } return 0; } </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Ok-Necessary-5859"> /u/Ok-Necessary-5859 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10l9d6o/printing_arrays_of_desired_lenght/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10l9d6o/printing_arrays_of_desired_lenght/">[comments]</a></span></content><id>t3_10l9d6o</id><link href="https://www.reddit.com/r/cprogramming/comments/10l9d6o/printing_arrays_of_desired_lenght/" /><updated>2023-01-25T20:52:11+00:00</updated><published>2023-01-25T20:52:11+00:00</published><title>Printing arrays of desired lenght</title></entry><entry><author><name>/u/Ianmurph91</name><uri>https://www.reddit.com/user/Ianmurph91</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I am an electrical guy, not a software guy so this is very new to me. I am trying to learn about polling right now. There is a frame writer that asserts a DONE bit when its done writing a video frame into memory. It only starts to write a new one when a GO bit is set. I am attempting to poll this status register for this DONE bit, and when it is high, I want to clear it and reset the GO bit. This was my first attempt, which is giving all sorts of Linux errors and crashing the system:</p> <pre><code>uint32_t status_reg = 0; uint8_t done_flag = 0; uint16_t frame_counter = 0; uint16_t num_frames = 3; static uint16_t iw_status_offset = 13; static uint16_t iw_control_offset = 0; uint32_t *writer = (uint32_t *)(writer_base_addr); // Poll the done_flag - bit [16] of status_reg while(frame_counter &lt; num_frames){ status_reg = writer[iw_status_offset]; printf(&quot;Value of status_reg = 0x%08X\n&quot;, status_reg); done_flag = (status_reg&gt;&gt;16)&amp;0x1; // extract bit 16 printf(&quot;Value of done_flag = %0d\n&quot;, done_flag); if(done_flag == 1){ frame_counter++; printf(&quot;Frame %0d done. Clearing done_flag and setting &#39;GO&#39; bit\n&quot;, frame_counter); writer[iw_control_offset] |= 1 &lt;&lt; 16; // Set bit [16] in control reg to clear the done_flag writer[iw_control_offset] |= 1 &lt;&lt; 0; // Set bit [0] in control reg to write another frame printf(&quot;Value of status_reg after clearing done_flag = 0x%08X\n&quot;, writer[iw_status_offset]); } } </code></pre> <p>I have learned that this is definitely not the correct way poll a register. I see there is a poll() function, but I am sort of confused how to use it for this situation. Can anyone provide some advice or point me to some similar examples?</p> <p>Thanks in advance</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Ianmurph91"> /u/Ianmurph91 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10l59sh/how_do_i_poll_a_status_register_and_wait_for_a/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10l59sh/how_do_i_poll_a_status_register_and_wait_for_a/">[comments]</a></span></content><id>t3_10l59sh</id><link href="https://www.reddit.com/r/cprogramming/comments/10l59sh/how_do_i_poll_a_status_register_and_wait_for_a/" /><updated>2023-01-25T18:11:02+00:00</updated><published>2023-01-25T18:11:02+00:00</published><title>How do I poll a status register and wait for a bit to be high?</title></entry><entry><author><name>/u/FIREOFDOOM2000</name><uri>https://www.reddit.com/user/FIREOFDOOM2000</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I have a char array that’s basically a string buffer. I want to use sprintf to copy only a certain range of characters. However I’m having a hard time finding a way to specify an end range. So far I’ve seen ways to start at an index and copy till the end, or start at the end and go back a certain amount. </p> <p>But I want the syntax to specify an intermediate range such as indexes 5-8 and copy only those values. </p> <p>Is there an appropriate syntax for such an option?</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/FIREOFDOOM2000"> /u/FIREOFDOOM2000 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10l6f1z/sprintf_for_characters_in_middle_of_char_arrays/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10l6f1z/sprintf_for_characters_in_middle_of_char_arrays/">[comments]</a></span></content><id>t3_10l6f1z</id><link href="https://www.reddit.com/r/cprogramming/comments/10l6f1z/sprintf_for_characters_in_middle_of_char_arrays/" /><updated>2023-01-25T18:55:49+00:00</updated><published>2023-01-25T18:55:49+00:00</published><title>sprintf for characters in middle of char arrays</title></entry><entry><author><name>/u/IAmAdicktedTo</name><uri>https://www.reddit.com/user/IAmAdicktedTo</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hello, I am doing the CS50 course and am currently on week 1. This week we are doing C programming. The problem for this week is to ask about the height of a pyramid and then print a pyramid of &quot;#&quot; side by side. I would also like to mention for the sake of making sense that the pyramid is split down the middle. Currently, I am able to print a pyramid of the height between 1 and 9 (Which are the bounds) however I am unable to split the pyramid down the middle nor have I been able to figure out how to keep the pyramids side by side. Below I have the code I have been able to figure out so far. Thank you to whoever helps or even sees this post.</p> <p><a href="https://cs50.harvard.edu/x/2023/psets/1/mario/more/">https://cs50.harvard.edu/x/2023/psets/1/mario/more/</a></p> <p>&#x200B;</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;cs50.h&gt; int main(void) { // inputting height of pyramid int height = 0; do { height = get_int(&quot;Please enter height: &quot;); } while (height &gt; 9 || height &lt; 1 ); // drawing the pyramid for (int x = 1; x &lt;= height; x++) { for(int y = 1; y &lt;= (height-x); y++) { printf(&quot; &quot;); } for(int z = 1; z&lt;=(2*x-1); z++) { printf(&quot;#&quot;); } printf(&quot;\n&quot;); } } </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/IAmAdicktedTo"> /u/IAmAdicktedTo </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10ksiub/a_student_asking_for_help/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10ksiub/a_student_asking_for_help/">[comments]</a></span></content><id>t3_10ksiub</id><link href="https://www.reddit.com/r/cprogramming/comments/10ksiub/a_student_asking_for_help/" /><updated>2023-01-25T06:53:17+00:00</updated><published>2023-01-25T06:53:17+00:00</published><title>A student asking for help.</title></entry><entry><author><name>/u/Any_Employ_1005</name><uri>https://www.reddit.com/user/Any_Employ_1005</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hey everyone, I&#39;m a complete beginner in programming and I&#39;ve just tried out simple programs for different functions and recently made a calculators. Can someone tell me what programs should I practice next as a beginner c programmer that require some kind of problem solving but at the same time they are not too much overwhelming for a beginner like me.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Any_Employ_1005"> /u/Any_Employ_1005 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10kfjqu/suggestions_for_beginner_programs_to_practice/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10kfjqu/suggestions_for_beginner_programs_to_practice/">[comments]</a></span></content><id>t3_10kfjqu</id><link href="https://www.reddit.com/r/cprogramming/comments/10kfjqu/suggestions_for_beginner_programs_to_practice/" /><updated>2023-01-24T20:38:08+00:00</updated><published>2023-01-24T20:38:08+00:00</published><title>Suggestions for beginner programs to practice.</title></entry><entry><author><name>/u/Ok-Necessary-5859</name><uri>https://www.reddit.com/user/Ok-Necessary-5859</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>i have found a code on the internet which I need for a part of a code that I am writing . Now this code works great, its supposed to find the minimal number and that&#39;s exactly what it does . My question however is in the logics of the code, I&#39;m new to programming and it doesn&#39;t make sense to me</p> <pre><code>include&lt;stdio.h&gt; int main () { int num, remainder; printf (&quot;Enter the Number :&quot;); scanf (&quot;%d&quot;, &amp;num); int smallest=num%10; while (num &gt; 0) { remainder = num % 10; if (smallest&gt; remainder) { smallest = remainder; } num = num / 10; } printf (&quot;The Smallest Digit is :%d \n&quot;, smallest); return 0; } </code></pre> <p>Before this part here where the program starts checking if, why isn&#39;t remainder equal to smallest? Both of their operations is num % 10 until this point</p> <pre><code>if (smallest&gt; remainder) { smallest = remainder; } </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Ok-Necessary-5859"> /u/Ok-Necessary-5859 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10khryx/understanding_while_loops/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10khryx/understanding_while_loops/">[comments]</a></span></content><id>t3_10khryx</id><link href="https://www.reddit.com/r/cprogramming/comments/10khryx/understanding_while_loops/" /><updated>2023-01-24T22:07:27+00:00</updated><published>2023-01-24T22:07:27+00:00</published><title>Understanding while loops</title></entry><entry><author><name>/u/Future_Shape_4119</name><uri>https://www.reddit.com/user/Future_Shape_4119</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html">&#32; submitted by &#32; <a href="https://www.reddit.com/user/Future_Shape_4119"> /u/Future_Shape_4119 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10kqhdq/how_can_i_get_good_at_c_and_cwithin_4months/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10kqhdq/how_can_i_get_good_at_c_and_cwithin_4months/">[comments]</a></span></content><id>t3_10kqhdq</id><link href="https://www.reddit.com/r/cprogramming/comments/10kqhdq/how_can_i_get_good_at_c_and_cwithin_4months/" /><updated>2023-01-25T04:53:56+00:00</updated><published>2023-01-25T04:53:56+00:00</published><title>How can I get good at C and C++within 4months?:""")</title></entry><entry><author><name>/u/Ok_Move_7139</name><uri>https://www.reddit.com/user/Ok_Move_7139</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hi friends ! </p> <p>For school, I need to do my own printf() function. Printf has ont behaviour that I cant figure out exactly. When you pass a negative integer to printf() with the %x or %X specifier, it does a weird thing where it kinda signed the result (i guess? Maybe? Im kinda new to C and hex). </p> <pre><code>Decimal -58 Printf(%x) = ffffffc6 Decimal -4324 Printf(%x) = ffffef1c </code></pre> <p>If someone has time to simply explain to me... how does it works? Like, why it does that ? Its probably something I dont get with Hexadecimals.</p> <p>thanks soo much and have a nice night !</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Ok_Move_7139"> /u/Ok_Move_7139 </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10jr67t/cant_figure_out_what_exactly_happens_when_yo_pass/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10jr67t/cant_figure_out_what_exactly_happens_when_yo_pass/">[comments]</a></span></content><id>t3_10jr67t</id><link href="https://www.reddit.com/r/cprogramming/comments/10jr67t/cant_figure_out_what_exactly_happens_when_yo_pass/" /><updated>2023-01-23T23:36:31+00:00</updated><published>2023-01-23T23:36:31+00:00</published><title>Can't figure out what exactly happens when yo pass a negative int to %x in printf</title></entry><entry><author><name>/u/Captain_barbarosa</name><uri>https://www.reddit.com/user/Captain_barbarosa</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hello everyone, Is there any sources to learn about software integration (in C &amp; C++) for example: how to build in release mode vs debug mode, compiler flags, make files and Cmake and what does deploy means and all the stuff related to software integration</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Captain_barbarosa"> /u/Captain_barbarosa </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10jmjgf/help_me_to_learn_about_software_integration/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10jmjgf/help_me_to_learn_about_software_integration/">[comments]</a></span></content><id>t3_10jmjgf</id><link href="https://www.reddit.com/r/cprogramming/comments/10jmjgf/help_me_to_learn_about_software_integration/" /><updated>2023-01-23T20:27:32+00:00</updated><published>2023-01-23T20:27:32+00:00</published><title>Help me to learn about software integration</title></entry><entry><author><name>/u/Deep_T</name><uri>https://www.reddit.com/user/Deep_T</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>Hi, I would like some help on some code I’ve been writing. I’m a beginner, and this is a project I’ve been doing just for fun. The code is:</p> <p><a href="https://pastebin.com/55UXjQg8">https://pastebin.com/55UXjQg8</a></p> <p>It is basically a game with a menu, a saving option and an error handler. Everything works fine, except for the errhandler function. It makes sure you don’t input a value that does not correspond with an action in game. It requires 10 input (it requires so much because maybe in the future the game will have many options to choose, so I wanted to be prepared for that), checks if it is a legal value and if it’s not exits the game. int i1 is the value that corresponds to the one obtained as an input from choosing the option in game, saved in save[i-1]. I filled the unused slots with a repeating legal value (explaining all the 0s). Apparently even if I inject invalid values in save[i-1] the function won’t stop the game, as if the value was legal. I tried using &amp;save[i-1] as input to the function and it works, so I think I’m injecting the value into the function in a wrong way. Can someone help me? You would help me to have a better sleep tonight haha. Thank you.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Deep_T"> /u/Deep_T </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10jq5w4/help_beginner_problem_function_does_not_start/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10jq5w4/help_beginner_problem_function_does_not_start/">[comments]</a></span></content><id>t3_10jq5w4</id><link href="https://www.reddit.com/r/cprogramming/comments/10jq5w4/help_beginner_problem_function_does_not_start/" /><updated>2023-01-23T22:54:36+00:00</updated><published>2023-01-23T22:54:36+00:00</published><title>[HELP] BEGINNER PROBLEM: function does not start when it should</title></entry><entry><author><name>/u/ZoidLay</name><uri>https://www.reddit.com/user/ZoidLay</uri></author><category term="cprogramming" label="r/cprogramming"/><content type="html"><!-- SC_OFF --><div class="md"><p>I compile the code using GCC 11.3.0 in linux mint</p> <p>gcc filename.c -o filename</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; int main() { char alphabet[] = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;; printf(&quot;%d&quot;, strlen(alphabet)); return 0; } </code></pre> <p>Why do I get this Warning? What is the correct way? if I change %d to %lu the Warning goes away but why?</p> <pre><code>strlen.c: In function ‘main’: strlen.c:6:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=] 6 | printf(&quot;%d&quot;, strlen(alphabet)); | ~^ ~~~~~~~~~~~~~~~~ | | | | int size_t {aka long unsigned int} | %ld </code></pre> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/ZoidLay"> /u/ZoidLay </a> <br/> <span><a href="https://www.reddit.com/r/cprogramming/comments/10jf3nx/c_strlen_warning/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/cprogramming/comments/10jf3nx/c_strlen_warning/">[comments]</a></span></content><id>t3_10jf3nx</id><link href="https://www.reddit.com/r/cprogramming/comments/10jf3nx/c_strlen_warning/" /><updated>2023-01-23T15:28:04+00:00</updated><published>2023-01-23T15:28:04+00:00</published><title>C strlen Warning</title></entry></feed> |