﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Programming Help Forums / Other Languages / C </title><generator>InstantForum.NET v4.1.4</generator><description>Programming Help Forums</description><link>http://programminghelp.com/forums/</link><webMaster>forums@programminghelp.com</webMaster><lastBuildDate>Fri, 18 May 2012 09:05:31 GMT</lastBuildDate><ttl>20</ttl><item><title>Beginner question: string arrays</title><link>http://programminghelp.com/forums/Topic8031-39-1.aspx</link><description>I've just started working on a simple shell-program. Currently reading user input works fine, but I'm having trouble splitting the input string into smaller strings of one word each, stored in the 2d array param. Here's an example of my desired result:&lt;br&gt;&lt;br&gt;input: "hello my name is bob -f"&lt;br&gt;&lt;br&gt;param[0] = "hello"&lt;br&gt;param[1] = "my"&lt;br&gt;param[2] = "name"&lt;br&gt;param[3] = "is"&lt;br&gt;param[4] = "bob"&lt;br&gt;param[5] = "-f"&lt;br&gt;&lt;br&gt;So far, my code looks like this:&lt;br&gt;&lt;br&gt;[quote]#include &gt;stdio.h&gt;&lt;br&gt;#include &gt;stdlib.h&gt;&lt;br&gt;#include &gt;ctype.h&gt;&lt;br&gt;#include &gt;string.h&gt;&lt;br&gt;&lt;br&gt;#define DEBUG&lt;br&gt;&lt;br&gt;int split(char *input, char **param)&lt;br&gt;{&lt;br&gt;}&lt;br&gt;&lt;br&gt;int main(void)&lt;br&gt;{&lt;br&gt;  while (1) {&lt;br&gt;    //Reads input&lt;br&gt;    printf("%s@inf1060-sh&gt;", getenv("USER"));&lt;br&gt;    char input[120];&lt;br&gt;    fflush(stdout);&lt;br&gt;    if (fgets(input, sizeof input, stdin) == NULL) return 0;&lt;br&gt;&lt;br&gt;    #ifdef DEBUG&lt;br&gt;    fprintf(stderr,"%s", input);&lt;br&gt;    #endif&lt;br&gt;    &lt;br&gt;    char *param[21];&lt;br&gt;    param[0][0] = 'a';&lt;br&gt;    &lt;br&gt;    int emptyIn = split(input, param);&lt;br&gt;  }&lt;br&gt;}&lt;br&gt;[/quote]&lt;br&gt;&lt;br&gt;This is not the entirety of my code, but the crash happens here.&lt;br&gt;&lt;br&gt;The arrows in the header-inclusions (what do I call them?) are switched around here so the content of them aren't left out.&lt;br&gt;&lt;br&gt;Now what I'm wondering is:&lt;br&gt;&lt;br&gt;why does &lt;br&gt;[quote]param[0][0] = 'a';[/quote]&lt;br&gt;give segmentation fault?&lt;br&gt;How do I fix this?&lt;br&gt;&lt;br&gt;Thanks in advance</description><pubDate>Wed, 05 Oct 2011 08:41:12 GMT</pubDate><dc:creator>Arcan</dc:creator></item><item><title>Struct Problems storing Client IP-address</title><link>http://programminghelp.com/forums/Topic7782-39-1.aspx</link><description>Hi everyone,&lt;br&gt;I got stuck again, this time with a different problem though. Writing on a little chat server based on “Beej’s Guide to Network Programming” and I tried to save each incoming connection into an array, so that every time a client posts something that it also will echo the clients IP-address.&lt;br&gt;For example:&lt;br&gt;127.0.0.1: Hello, anybody out there?&lt;br&gt;&lt;br&gt;I got everything working but right now I just display following output:&lt;br&gt;Socket 4: Hello, anybody out there?&lt;br&gt;&lt;br&gt;So in order to store the IP addresses as soon as a client connects, I created following struct.&lt;br&gt;&lt;br&gt;[code]&lt;br&gt;struct connection&lt;br&gt;{&lt;br&gt;	const char *IPv4_addr;&lt;br&gt;};&lt;br&gt;[/code]&lt;br&gt;&lt;br&gt;And created an array variable of type struct connection;&lt;br&gt;[code]&lt;br&gt;struct connection client[6];	// client information&lt;br&gt;[/code]&lt;br&gt;&lt;br&gt;Then I try to store the client IP in this array and I use the following command:&lt;br&gt;[code]&lt;br&gt;client[newfd].IPv4_addr=inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&amp;remoteaddr),remoteIP, INET_ADDRSTRLEN);&lt;br&gt; [/code]&lt;br&gt;&lt;br&gt;Here is the function it is in&lt;br&gt;[code]&lt;br&gt;//----------------------------------------------------------&lt;br&gt;// CHECK EXISTING CONNECTIONS FOR DATA&lt;br&gt;//------------------------------------&lt;br&gt;for(i = 0; i &lt;= fdmax; i++)&lt;br&gt;{&lt;br&gt;	//------------------------------------------------------&lt;br&gt;	// CHECK FOR NEW CONNECTIONS&lt;br&gt;	//--------------------------&lt;br&gt;	if (FD_ISSET(i, &amp;read_fds))				// we got one!!&lt;br&gt;	{ &lt;br&gt;		if (i == listener)&lt;br&gt;		{&lt;br&gt;			// handle new connections&lt;br&gt;			addrlen = sizeof remoteaddr;&lt;br&gt;			newfd = accept(listener,(struct sockaddr *)&amp;remoteaddr,&amp;addrlen);&lt;br&gt;			if (newfd == -1)				// If connection attempt fails&lt;br&gt;			{&lt;br&gt;				perror("accept");&lt;br&gt;			}&lt;br&gt;			else&lt;br&gt;			{&lt;br&gt;				FD_SET(newfd, &amp;master);		// add to master set&lt;br&gt;				if (newfd &gt; fdmax)			// keep track of the max&lt;br&gt;				{&lt;br&gt;					fdmax = newfd;&lt;br&gt;				}&lt;br&gt;			client[newfd].IPv4_addr=inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&amp;remoteaddr),remoteIP, INET_ADDRSTRLEN);&lt;br&gt;			printf("selectserver: new connection from %s on socket %d",&lt;br&gt;	/* -&gt; */	inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&amp;remoteaddr),remoteIP, INET6_ADDRSTRLEN),newfd);&lt;br&gt;			}&lt;br&gt;		}&lt;br&gt;[/code]&lt;br&gt;&lt;br&gt;And right in that line where it says:&lt;br&gt;[code]&lt;br&gt;client[newfd].IPv4_addr=inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&amp;remoteaddr),remoteIP, INET_ADDRSTRLEN);&lt;br&gt;[/code]&lt;br&gt;&lt;br&gt;Is my problem, since I’m using a pointer and it always clear the entire content of that variable as soon as another client connects because it keeps pointing to the same spot in the memory. It works perfectly fine for a single connection (of course…..)&lt;br&gt;Now I unfortunately can’t change it, since the function I use in that same line requires a pointer at that time I call it.&lt;br&gt;So what else could I do, to bypass this problem and somehow store each clients IP-address in that client array of type struct connection?&lt;br&gt;&lt;br&gt;I hope You understand what exactly my problem is.&lt;br&gt;The entire code is attached in a .zip file.&lt;br&gt;&lt;br&gt;&lt;br&gt;I really hope you guys can help me out and I’d appreciate each suggestion that leads me the right way, since this is bugging me for a few days now.&lt;br&gt;&lt;br&gt;Thanks,&lt;br&gt;~Stud&lt;br&gt;</description><pubDate>Thu, 22 Sep 2011 22:03:18 GMT</pubDate><dc:creator>studiologe</dc:creator></item><item><title>Infix/postfix &amp; bc and dc conversion</title><link>http://programminghelp.com/forums/Topic7750-39-1.aspx</link><description>Hi, thank you for taking the time to take a look at this.&lt;br&gt;&lt;br&gt;So here's the deal, my assignment is to write a program that resembles the traditional version of bc. It will translate the more common way of writing arithmetic expressions into postfix form used by the dc utility.&lt;br&gt;Ok, so there is plenty of info how to write a program to convert to postfix notation, therefore thats not the issue. The issue being, I can't find any info on the bc/dc utilities, and can't really figure out how they choose their output, other than testing thousands of entries and expressions over and over. Our teacher simply expects us to be pros at the unix environment without any prior knowledge or lessons.&lt;br&gt;&lt;br&gt;Examples of input and output, respectively.&lt;br&gt;1+2*3 -- 1 2 3*+ps&lt;br&gt;i=+2; -- li 2+si&lt;br&gt;a=b=c=0 -- 0dscdsbsa&lt;br&gt;&lt;br&gt;if(x&lt;4) -- [ 2sy ]s0&lt;br&gt;y=2; -- lx 4&gt;0&lt;br&gt;&lt;br&gt;Thanks for any help you may provide.&lt;br&gt;Paul</description><pubDate>Sun, 18 Sep 2011 17:50:25 GMT</pubDate><dc:creator>sheepdogg09</dc:creator></item><item><title>Role of function</title><link>http://programminghelp.com/forums/Topic7608-39-1.aspx</link><description>What is role of functions in C++ and how they are used?</description><pubDate>Tue, 09 Aug 2011 17:24:59 GMT</pubDate><dc:creator>SeoDezin</dc:creator></item><item><title>Beginner Advice Needed</title><link>http://programminghelp.com/forums/Topic5369-39-1.aspx</link><description>I am Virtual Assistant working for a group of web developer. Because of this kind of task I became interested in programming. Can someone provide me with resources for want to be programmer.</description><pubDate>Fri, 15 Oct 2010 04:49:57 GMT</pubDate><dc:creator>John Roger</dc:creator></item><item><title>What is the difference between ++var and var++?</title><link>http://programminghelp.com/forums/Topic7534-39-1.aspx</link><description>The &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;++&lt;/FONT&gt; operator is called the increment operator. When the operator is placed before the variable (&lt;FONT color=#dd0000 size=2 face="Courier New"&gt;++var&lt;/FONT&gt;), the variable is incremented by 1 before it is used in the expression. When the operator is placed after the variable (&lt;FONT color=#dd0000 size=2 face="Courier New"&gt;var++&lt;/FONT&gt;), the expression is evaluated, and then the variable is incremented by 1.&lt;/P&gt;&lt;P&gt;The same holds true for the decrement operator (&lt;FONT color=#dd0000 size=2 face="Courier New"&gt;--&lt;/FONT&gt;). When the operator is placed before the variable, you are said to have a prefix operation. When the operator is placed after the variable, you are said to have a postfix operation.&lt;/P&gt;&lt;P&gt;For instance, consider the following example of postfix incrementation:&lt;/P&gt;&lt;PRE class=code-pre&gt;&lt;CODE class=cpp&gt;&lt;SPAN class=keyword&gt;int&lt;/SPAN&gt; x, y;x = &lt;SPAN class=number&gt;1&lt;/SPAN&gt;;y = (x++ * &lt;SPAN class=number&gt;5&lt;/SPAN&gt;);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, postfix incrementation is used, and &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;x&lt;/FONT&gt; is not incremented until after the evaluation of the expression is done. Therefore, &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;y&lt;/FONT&gt; evaluates to 1 times 5, or 5. After the evaluation, &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;x&lt;/FONT&gt; is incremented to 2.&lt;/P&gt;&lt;P&gt;Now look at an example using prefix incrementation:&lt;/P&gt;&lt;PRE class=code-pre&gt;&lt;CODE class=cpp&gt;&lt;SPAN class=keyword&gt;int&lt;/SPAN&gt; x, y;x = &lt;SPAN class=number&gt;1&lt;/SPAN&gt;;y = (++x * &lt;SPAN class=number&gt;5&lt;/SPAN&gt;);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This example is the same as the first one, except that this example uses prefix incrementation rather than postfix. Therefore, &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;x&lt;/FONT&gt; is incremented before the expression is evaluated, making it 2. Hence, &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;y&lt;/FONT&gt; evaluates to 2 times 5, or 10.</description><pubDate>Sat, 25 Jun 2011 06:11:03 GMT</pubDate><dc:creator>myprogramminghelpforum</dc:creator></item><item><title>When is a switch statement better than multiple if statements?</title><link>http://programminghelp.com/forums/Topic7533-39-1.aspx</link><description>A &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;switch&lt;/FONT&gt; statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code&lt;/P&gt;&lt;PRE class=code-pre&gt;&lt;CODE class=cpp&gt;&lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (x == &lt;SPAN class=number&gt;1&lt;/SPAN&gt;)     printf(&lt;SPAN class=string&gt;"x is equal to one."&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;else&lt;/SPAN&gt; &lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (x == &lt;SPAN class=number&gt;2&lt;/SPAN&gt;)     printf(&lt;SPAN class=string&gt;"x is equal to two."&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;else&lt;/SPAN&gt; &lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (x == &lt;SPAN class=number&gt;3&lt;/SPAN&gt;)     printf(&lt;SPAN class=string&gt;"x is equal to three."&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;else&lt;/SPAN&gt;     printf(&lt;SPAN class=string&gt;"x is not equal to one, two, or three."&lt;/SPAN&gt;);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the following code is easier to read and maintain:&lt;/P&gt;&lt;PRE class=code-pre&gt;&lt;CODE class=cpp&gt;&lt;SPAN class=keyword&gt;switch&lt;/SPAN&gt; (x){     &lt;SPAN class=keyword&gt;case&lt;/SPAN&gt; &lt;SPAN class=number&gt;1&lt;/SPAN&gt;:   printf(&lt;SPAN class=string&gt;"x is equal to one."&lt;/SPAN&gt;);                    &lt;SPAN class=keyword&gt;break&lt;/SPAN&gt;;     &lt;SPAN class=keyword&gt;case&lt;/SPAN&gt; &lt;SPAN class=number&gt;2&lt;/SPAN&gt;:   printf(&lt;SPAN class=string&gt;"x is equal to two."&lt;/SPAN&gt;);                    &lt;SPAN class=keyword&gt;break&lt;/SPAN&gt;;     &lt;SPAN class=keyword&gt;case&lt;/SPAN&gt; &lt;SPAN class=number&gt;3&lt;/SPAN&gt;:   printf(&lt;SPAN class=string&gt;"x is equal to three."&lt;/SPAN&gt;);                    &lt;SPAN class=keyword&gt;break&lt;/SPAN&gt;;     &lt;SPAN class=keyword&gt;default&lt;/SPAN&gt;:  printf(&lt;SPAN class=string&gt;"x is not equal to one, two, or three."&lt;/SPAN&gt;);                    &lt;SPAN class=keyword&gt;break&lt;/SPAN&gt;;}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Notice that for this method to work, the conditional expression must be based on a variable of numeric type in order to use the switch statement. Also, the conditional expression must be based on a single variable. For instance, even though the following &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;if&lt;/FONT&gt; statement contains more than two conditions, it is not a candidate for using a &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;switch&lt;/FONT&gt; statement because it is based on string comparisons and not numeric comparisons:&lt;/P&gt;&lt;PRE class=code-pre&gt;&lt;CODE class=cpp&gt;&lt;SPAN class=keyword&gt;char&lt;/SPAN&gt;* name = &lt;SPAN class=string&gt;"Lupto"&lt;/SPAN&gt;;&lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (!stricmp(name, &lt;SPAN class=string&gt;"Isaac"&lt;/SPAN&gt;))     printf(&lt;SPAN class=string&gt;"Your name means 'Laughter'."&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;else&lt;/SPAN&gt; &lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (!stricmp(name, &lt;SPAN class=string&gt;"Amy"&lt;/SPAN&gt;))     printf(&lt;SPAN class=string&gt;"Your name means 'Beloved'. "&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;else&lt;/SPAN&gt; &lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (!stricmp(name, &lt;SPAN class=string&gt;"Lloyd"&lt;/SPAN&gt;))     printf(&lt;SPAN class=string&gt;"Your name means 'Mysterious'. "&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;else&lt;/SPAN&gt;     printf(&lt;SPAN class=string&gt;"I haven't a clue as to what your name means."&lt;/SPAN&gt;);&lt;/CODE&gt;&lt;/PRE&gt;</description><pubDate>Sat, 25 Jun 2011 06:09:59 GMT</pubDate><dc:creator>myprogramminghelpforum</dc:creator></item><item><title>What is a local block?</title><link>http://programminghelp.com/forums/Topic7532-39-1.aspx</link><description>A local block is any portion of a C program that is enclosed by the left brace (&lt;FONT color=#dd0000 size=2 face="Courier New"&gt;{&lt;/FONT&gt;) and the right brace (&lt;FONT color=#dd0000 size=2 face="Courier New"&gt;}&lt;/FONT&gt;). A C function contains left and right braces, and therefore anything between the two braces is contained in a local block. An &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;if&lt;/FONT&gt; statement or a &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;switch&lt;/FONT&gt; statement can also contain braces, so the portion of code between these two braces would be considered a local block.&lt;/P&gt;&lt;P&gt;Additionally, you might want to create your own local block without the aid of a C function or keyword construct. This is perfectly legal. Variables can be declared within local blocks, but they must be declared only at the beginning of a local block. Variables declared in this manner are visible only within the local block. Duplicate variable names declared within a local block take precedence over variables with the same name declared outside the local block. Here is an example of a program that uses local blocks:&lt;/P&gt;&lt;PRE class=code-pre&gt;&lt;CODE class=cpp&gt;&lt;SPAN class=preprocessor&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=keyword&gt;void&lt;/SPAN&gt; main(&lt;SPAN class=keyword&gt;void&lt;/SPAN&gt;);&lt;SPAN class=keyword&gt;void&lt;/SPAN&gt; main(){     &lt;SPAN class=comment&gt;/* Begin local block for function main() */&lt;/SPAN&gt;     &lt;SPAN class=keyword&gt;int&lt;/SPAN&gt; test_var = &lt;SPAN class=number&gt;10&lt;/SPAN&gt;;     printf(&lt;SPAN class=string&gt;"Test variable before the if statement: %d"&lt;/SPAN&gt;, test_var);     &lt;SPAN class=keyword&gt;if&lt;/SPAN&gt; (test_var &amp;gt; &lt;SPAN class=number&gt;5&lt;/SPAN&gt;)     {          &lt;SPAN class=comment&gt;/* Begin local block for "if" statement */&lt;/SPAN&gt;          &lt;SPAN class=keyword&gt;int&lt;/SPAN&gt; test_var = &lt;SPAN class=number&gt;5&lt;/SPAN&gt;;          printf(&lt;SPAN class=string&gt;"Test variable within the if statement: %d"&lt;/SPAN&gt;,                 test_var);          {               &lt;SPAN class=comment&gt;/* Begin independent local block (not tied to                  any function or keyword) */&lt;/SPAN&gt;               &lt;SPAN class=keyword&gt;int&lt;/SPAN&gt; test_var = &lt;SPAN class=number&gt;0&lt;/SPAN&gt;;               printf(               &lt;SPAN class=string&gt;"Test variable within the independent local block:%d"&lt;/SPAN&gt;,               test_var);          }          &lt;SPAN class=comment&gt;/* End independent local block */&lt;/SPAN&gt;     }     &lt;SPAN class=comment&gt;/* End local block for "if" statement */&lt;/SPAN&gt;     printf(&lt;SPAN class=string&gt;"Test variable after the if statement: %d"&lt;/SPAN&gt;, test_var);}&lt;SPAN class=comment&gt;/* End local block for function main() */&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This example program produces the following output:&lt;/P&gt;&lt;P&gt;Test variable before the &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;if&lt;/FONT&gt; statement: 10&lt;/P&gt;&lt;P&gt;Test variable within the &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;if&lt;/FONT&gt; statement: 5&lt;/P&gt;&lt;P&gt;Test variable within the independent local block: 0&lt;/P&gt;&lt;P&gt;Test variable after the &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;if&lt;/FONT&gt; statement: 10&lt;/P&gt;&lt;P&gt;Notice that as each test_var was defined, it took precedence over the previously defined &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;test_var&lt;/FONT&gt;. Also notice that when the &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;if&lt;/FONT&gt; statement local block had ended, the program had reentered the scope of the original &lt;FONT color=#dd0000 size=2 face="Courier New"&gt;test_var&lt;/FONT&gt;, and its value was 10.</description><pubDate>Sat, 25 Jun 2011 06:09:25 GMT</pubDate><dc:creator>myprogramminghelpforum</dc:creator></item><item><title>Array definition</title><link>http://programminghelp.com/forums/Topic3821-39-1.aspx</link><description>I wrote:&lt;br&gt;&lt;br&gt;int a[] = {&lt;br&gt;             0,0,1,0,0,&lt;br&gt;             0,1,0,1,0,&lt;br&gt;             1,0,0,0,1,&lt;br&gt;             1,1,1,1,1,&lt;br&gt;             1,0,0,0,1&lt;br&gt;             };&lt;br&gt;&lt;br&gt;The size of array is a[25] or a[5][5]?&lt;br&gt;Thx</description><pubDate>Sun, 24 May 2009 06:26:30 GMT</pubDate><dc:creator>misfi</dc:creator></item><item><title>The best compiler for C</title><link>http://programminghelp.com/forums/Topic3820-39-1.aspx</link><description>The best compiler for C under windows is....?&lt;br&gt;&lt;br&gt;I use DevC++...</description><pubDate>Sun, 24 May 2009 04:22:39 GMT</pubDate><dc:creator>misfi</dc:creator></item><item><title>assigning values to pointers inside a structure---urgent help needed!!!!!!!!!</title><link>http://programminghelp.com/forums/Topic6829-39-1.aspx</link><description>typedef struct x&lt;br&gt;{int a;&lt;br&gt;int b;&lt;br&gt;int *c;&lt;br&gt;}test;&lt;br&gt;i&lt;br&gt;nt main(void)&lt;br&gt;&lt;br&gt;{&lt;br&gt;&lt;br&gt;test.b=a2;&lt;br&gt;test-&gt;c=a2;&lt;br&gt;&lt;br&gt;printf(" c is %d", test1.c);&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;br&gt;How to assign a value to c?</description><pubDate>Sun, 15 May 2011 16:45:31 GMT</pubDate><dc:creator>abhisrk</dc:creator></item><item><title>How do I read string say -5/-10 and then reduce the first number and second number to lowest terms.?</title><link>http://programminghelp.com/forums/Topic6392-39-1.aspx</link><description>code so far:&lt;BR&gt;&lt;BR&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR&gt;#include &amp;lt;math.h&amp;gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;typedef struct frac{ /* a fraction, numer/denom */&lt;BR&gt;int numer; /* numerator of fraction */&lt;BR&gt;int denom; /* denominator of fraction */&lt;BR&gt;} frac;&lt;BR&gt;&lt;BR&gt;/* greatest common divisor */&lt;BR&gt;int gcd(int a, int b) &lt;BR&gt;{&lt;BR&gt;while (b != 0) {&lt;BR&gt;int temp = b;&lt;BR&gt;b = a%b;&lt;BR&gt;a = temp;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;return a;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;/* reduce z to lowest terms */&lt;BR&gt;struct frac reduce(struct frac x)&lt;BR&gt;{&lt;BR&gt;struct frac z;&lt;BR&gt;&lt;BR&gt;int c = gcd(x.numer, x.denom);&lt;BR&gt;z.numer = x.numer/c;&lt;BR&gt;z.denom = x.denom/c;&lt;BR&gt;&lt;BR&gt;return z;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;struct frac init(int a, int b)&lt;BR&gt;{&lt;BR&gt;struct frac z;&lt;BR&gt;&lt;BR&gt;if (b &amp;lt; 0) { /* put sign in the numerator */&lt;BR&gt;a = -a;&lt;BR&gt;b = -b;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;z.numer = a;&lt;BR&gt;z.denom = b;&lt;BR&gt;z = reduce(z);&lt;BR&gt;&lt;BR&gt;return z;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;int main(void)&lt;BR&gt;{&lt;BR&gt;int num, den;&lt;BR&gt;struct frac z;&lt;BR&gt;int c = 1;&lt;BR&gt;char str[50];&lt;BR&gt;&lt;BR&gt;printf("Input fraction (num/den): ");&lt;BR&gt;scanf("%s", str);&lt;BR&gt;&lt;BR&gt;scanf("%d%d", &amp;amp;num, &amp;amp;den);&lt;BR&gt;&lt;BR&gt;if((num==0) &amp;amp;&amp;amp; (den!=0)) &lt;BR&gt;{&lt;BR&gt;if(num&amp;gt;=0){&lt;BR&gt;num = -1*num;&lt;BR&gt;}&lt;BR&gt;printf("-%d/%d", num,den);&lt;BR&gt;printf(" = -%d/%d", num,c);&lt;BR&gt;return 0;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;if (den==0) &lt;BR&gt;{&lt;BR&gt;if(num&amp;gt;0){&lt;BR&gt;num = -1*num; &lt;BR&gt;printf("%d/%d", num,den);&lt;BR&gt;}&lt;BR&gt;else if (num==0){&lt;BR&gt;printf("-%d/%d", num,den); &lt;BR&gt;}&lt;BR&gt;printf("Floating exception");&lt;BR&gt;return 0;&lt;BR&gt;} &lt;BR&gt;&lt;BR&gt;printf("%d/%d", num,den);&lt;BR&gt;&lt;BR&gt;if ((den!=0) &amp;amp;&amp;amp; (num!=0)) &lt;BR&gt;{&lt;BR&gt;z = init(num,den);&lt;BR&gt;printf(" = %d/%d", z.numer,z.denom);&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;return 0;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;Example:&lt;BR&gt;&lt;BR&gt;Input is: -5/-10&lt;BR&gt;&lt;BR&gt;should return: 1/2</description><pubDate>Sun, 13 Mar 2011 03:47:25 GMT</pubDate><dc:creator>Nvoron23</dc:creator></item><item><title>forked child process not terminating.</title><link>http://programminghelp.com/forums/Topic5254-39-1.aspx</link><description>Hi,&lt;br&gt;I'm new to Linux,.&lt;br&gt;&lt;br&gt;Here is the problem,,&lt;br&gt;I'm trying out some c programs, i have problem when i fork a child process,,its not terminating , i,e program is entering into an infinite loop.. even ctr+c not working..&lt;br&gt;what wrong am I doing..?&lt;br&gt;please replay early..&lt;br&gt;thank you..</description><pubDate>Sun, 03 Oct 2010 09:22:04 GMT</pubDate><dc:creator>shrikanth</dc:creator></item><item><title>Do you know any GPL project written in C?</title><link>http://programminghelp.com/forums/Topic3819-39-1.aspx</link><description>Do you know any GPL project written in C?</description><pubDate>Sun, 24 May 2009 04:20:39 GMT</pubDate><dc:creator>misfi</dc:creator></item></channel></rss>
