<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>C Board - C Programming</title>
		<link>http://cboard.cprogramming.com/</link>
		<description>Questions specific to C Programming</description>
		<language>en</language>
		<lastBuildDate>Tue, 21 May 2013 18:08:39 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://cboard.cprogramming.com/images/misc/rss.png</url>
			<title>C Board - C Programming</title>
			<link>http://cboard.cprogramming.com/</link>
		</image>
		<item>
			<title>trouble with scanf and validating input</title>
			<link>http://cboard.cprogramming.com/c-programming/156913-trouble-scanf-validating-input.html</link>
			<pubDate>Tue, 21 May 2013 17:30:50 GMT</pubDate>
			<description><![CDATA[I need to use scanf to input an 8 digit number with no extra "junk" characters after the number (e.g. 12345678k), just the number, or else a prompt to re-enter. i know scanf isn't recommended but this is the second week of class and it's the only function of its kind we've learned so far ( besides...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->I need to use scanf to input an 8 digit number with no extra &quot;junk&quot; characters after the number (e.g. 12345678k), just the number, or else a prompt to re-enter. i know scanf isn't recommended but this is the second week of class and it's the only function of its kind we've learned so far ( besides getchar() for flushing the input buffer).<br />
<br />
this is what i have so far:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">/* <br />
&nbsp;  This program prompts the user to setup a pin<br />
&nbsp;  It handles invalid input properly <br />
*/<br />
<br />
#include &lt;stdio.h&gt;<br />
<br />
/* Complete the code for this program below */<br />
<br />
int main()<br />
{<br />
&nbsp; &nbsp; int acctNum, pinNum, temp, numDigits = 0;<br />
&nbsp; &nbsp; char ch;<br />
<br />
&nbsp; &nbsp; printf(&quot;Please enter your 8 digit account number: &quot;);<br />
&nbsp; &nbsp; scanf(&quot;%d%c&quot;, &amp;acctNum, &amp;ch);<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /* Calculates numbers of digits in number entered */<br />
&nbsp; &nbsp; temp = acctNum;<br />
&nbsp;  while(temp)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; temp = acctNum/10;<br />
&nbsp; &nbsp; &nbsp; numDigits++;<br />
&nbsp;  }<br />
<br />
&nbsp; &nbsp; while(numDigits != 8 || ch != '\n')<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; /* Flushes input buffer */<br />
&nbsp; &nbsp; &nbsp; &nbsp; while(getchar() != '\n');<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;  printf(&quot;Invalid account number. Account number must be 8 digits.\n\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Please enter your 8 digit account number: &quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; scanf(&quot;%d%c&quot;, &amp;acctNum, &amp;ch);<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; /* Calculates numbers of digits in number entered */<br />
&nbsp; &nbsp; &nbsp; &nbsp; while(temp)<br />
&nbsp; &nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  temp = acctNum/10;<br />
&nbsp; &nbsp; &nbsp; &nbsp;  numDigits++;<br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; return 0;<br />
}</code><hr />
</div>problem is, i  think i'm having trouble with the \n and scanf. here's what happens:<br />
<br />
If i input valid number first time = program ends succesfully<br />
<br />
If i input an invalid number first try (e.g. 123456789), i must press &lt;enter&gt; twice and then it prompts me to re-eneter, but every input after that is returned as invalid even if it is valid ( i also must press &lt;enter&gt; twice for all these inputs).<br />
<br />
where am i going wrong?<br />
<br />
thanks<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>fazio93</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156913-trouble-scanf-validating-input.html</guid>
		</item>
		<item>
			<title>Newbie Question</title>
			<link>http://cboard.cprogramming.com/c-programming/156911-newbie-question.html</link>
			<pubDate>Tue, 21 May 2013 15:32:45 GMT</pubDate>
			<description><![CDATA[Hello. I'm still pretty new to programming, and new to this board. 
 
Just have a question from a textbook. The code works, but I'm a little confused  about the control flow. 
 
Here's the code (actually, just a function from a larger hotel room reservation example program) 
 
 
Code: 
--------- 
...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hello. I'm still pretty new to programming, and new to this board.<br />
<br />
Just have a question from a textbook. The code works, but I'm a little confused  about the control flow.<br />
<br />
Here's the code (actually, just a function from a larger hotel room reservation example program)<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"> int find_room(struct hotel *h){<br />
<br />
int i;<br />
for(i=0; i&lt;10; i++){<br />
&nbsp; &nbsp; if(h-&gt;rooms[i] == 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; return i;}<br />
<br />
return -1;<br />
<br />
}</code><hr />
</div>My question is. The way it looks to me, it appears that return -1 will be returned no matter what. Obviously, this is not the case, because the program when run does (seem) to work correctly.<br />
<br />
So I can only assume that the way it is written, despite the way it *appears* to me that it logically should work, that -1 is only returned if the if statements return i DOESN'T get returned? Is that correct?<br />
<br />
I'd just never seen a function with two return statements, unless there was an else following that if statement, to pick one of the two, which there isn't. I guess that's why it seems strange to me.<br />
<br />
Any clarification / input appreciated.<br />
<br />
Thanks!<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>izqomar</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156911-newbie-question.html</guid>
		</item>
		<item>
			<title>For static variables when the memory will be allocated?</title>
			<link>http://cboard.cprogramming.com/c-programming/156909-static-variables-when-memory-will-allocated.html</link>
			<pubDate>Tue, 21 May 2013 08:42:23 GMT</pubDate>
			<description>Hi 
 
For static variables when the memory will be allocated? During compilation or linking or loading time? 
 
In below program i am getting error ( error C2099: initializer is not a  constant in microsoft visual studio) . If i initialize x = 10 or any  constant it works , why? Please help me in...</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi<br />
<br />
For static variables when the memory will be allocated? During compilation or linking or loading time?<br />
<br />
In below program i am getting error ( error C2099: initializer is not a  constant in microsoft visual studio) . If i initialize x = 10 or any  constant it works , why? Please help me in this issue<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><br />
main() { <br />
int i=10; <br />
static int x = i;//error ? <br />
if(x==i) <br />
printf(&quot;Equal&quot;); <br />
else if(x&gt;i) <br />
printf(&quot;Greater&quot;); <br />
else printf(&quot;Lesser&quot;); <br />
return 0; <br />
}</code><hr />
</div>thanks <br />
raghu<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>raghu_</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156909-static-variables-when-memory-will-allocated.html</guid>
		</item>
		<item>
			<title>Help w/ Multiple Client Socket Programming (UDP)</title>
			<link>http://cboard.cprogramming.com/c-programming/156908-help-w-multiple-client-socket-programming-udp.html</link>
			<pubDate>Tue, 21 May 2013 07:14:19 GMT</pubDate>
			<description><![CDATA[[TR] 
[TD="class: alt1, bgcolor: #EFEFEF"]Hi guys, I need some help with socket programming using UDP. I had successfully connected to a server run by another host, but my problem now is to be able to chat with other users or clients in that server. I'm not sure if my messaged actually got through...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start --><div class="cms_table"><table class="cms_table_tborder" width="100%" align="center"><tr valign="top" class="cms_table_tborder_tr"><TD class="cms_table_alt1 cms_table_tborder_td" style="background-color: #EFEFEF">Hi guys, I need some help with socket programming using UDP. I had successfully connected to a server run by another host, but my problem now is to be able to chat with other users or clients in that server. I'm not sure if my messaged actually got through to the user when prompted. Need some help heading in the right direction.. Thank you! Here are my codes for the client webchat:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><b><br />
/* variables used */ </b><br />
int i; //the very famous for-loop counter <br />
int check; //this variable store the return values of sendto and receive functions to make sure transmission is correct <br />
<br />
char username[16]; <br />
int userfound; //flag that is set to 1 when user name type in exists <br />
char message_sent[MAX_MSG_LEN]; <br />
int len; //message length <br />
int UDP_socket; s<br />
truct sockaddr_in chateeAddr; //address of user you want to chat to <br />
char prompt[10]; //user response when asked to continue chatting<br />
<br />
<br />
<b>/*the first step is to get a UDP socket */ <br />
</b>UDP_socket = socket(AF_INET, SOCK_DGRAM, 0); char b1[100], b2[100]; <br />
<br />
<b><br />
//the second step is to store the information of server inside </b><br />
the chateeAddr structure, <br />
bzero((char *)&amp;chateeAddr,sizeof(chateeAddr)); chateeAddr.sin_family = AF_INET; <br />
chateeAddr.sin_port = UDPchatee.portnumber; chateeAddr.sin_addr.s_addr = UDPchatee.userIP; memset(chateeAddr.sin_zero, '\0', sizeof chateeAddr.sin_zero); <br />
int n = sizeof(chateeAddr); <br />
<br />
while(1) { <br />
//get message you want to send <br />
printf(&quot;Enter a line of text as your message \n&quot;); gets(b2); <br />
printf(&quot;You entered: %s&quot;, b2); sendto(UDP_socket,message_sent,sizeof(message_sent),0,(struct sockaddr *)&amp;chateeAddr,n); <br />
<br />
if(strcmp(b2,&quot;end&quot;)==0) <br />
break; recvfrom(UDP_socket,b1,sizeof(b1),0,NULL,NULL); printf(&quot;\nReply:%s&quot;,b1); } <br />
<br />
<b>//the final steps is to shut down and close connection </b>shutdown ( UDP_socket , 2 ); <br />
close ( UDP_socket ); <br />
for (i = 0; i&lt;10; i++) <br />
prompt[i] = '\0'; <br />
printf(&quot;Please type 'exit' to exit, or anything else to continue chattingg\n&quot;); <br />
fgets(prompt, MAX_MSG_LEN, stdin); <br />
<br />
if (strcmp(prompt, &quot;exit\n&quot;) == 0) <br />
break; //close the UDP socket and exit <br />
} <br />
close ( UDP_socketID ); <br />
return 0; <br />
}</TD>
</tr>
</table></div>
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"></code><hr />
</div><!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>Peanutty</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156908-help-w-multiple-client-socket-programming-udp.html</guid>
		</item>
		<item>
			<title>Function within a function</title>
			<link>http://cboard.cprogramming.com/c-programming/156907-function-within-function.html</link>
			<pubDate>Tue, 21 May 2013 06:12:44 GMT</pubDate>
			<description><![CDATA[I'm thinking of making a function that passes functions as parameters. I'm not sure how to do it though...this is my stab at it. 
 
Code: 
--------- 
void CalcOps(void ovtHrs(&record[i].hrs_wrk, &record[i].ovt_hrs, record[i].hrs, &record[i].gross, record[i].payrate), void...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->I'm thinking of making a function that passes functions as parameters. I'm not sure how to do it though...this is my stab at it.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">void CalcOps(void ovtHrs(&amp;record[i].hrs_wrk, &amp;record[i].ovt_hrs, record[i].hrs, &amp;record[i].gross, record[i].payrate), void calculatetaxes(record[i].gross, record[i].deferred, &amp;record[i].ft, &amp;record[i].st, &amp;record[i].ssi), void netPay(record[i].gross, record[i].deferred, record[i].ft, record[i].st, record[i].ssi, &amp;record[i].net), void calcAccumulator(&amp;tot_payrate, record[i].payrate, &amp;tot_hrs_wrk, record[i].hrs_wrk, &amp;tot_ovt, record[i].ovt_hrs, &amp;tot_gross, record[i].gross, &amp;tot_ft, record[i].ft, &amp;tot_st, record[i].st, &amp;tot_ssi, record[i].ssi, &amp;tot_deferred, record[i].deferred, &amp;tot_net, record[i].net), void calcAverage(tot_payrate, &amp;payrate_avg, tot_hrs_wrk, &amp;hrs_wrk_avg, tot_ovt, &amp;ovt_avg, tot_gross, &amp;gross_avg, tot_ft, &amp;ft_avg, tot_st, &amp;st_avg, tot_ssi, &amp;ssi_avg, tot_deferred, &amp;deferred_avg, tot_net, &amp;net_avg));</code><hr />
</div>Or do i just pass the variables in the functions?<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>arti</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156907-function-within-function.html</guid>
		</item>
		<item>
			<title>Need help keeps looping</title>
			<link>http://cboard.cprogramming.com/c-programming/156906-need-help-keeps-looping.html</link>
			<pubDate>Tue, 21 May 2013 05:21:55 GMT</pubDate>
			<description><![CDATA[Code: 
--------- 
#include <stdio.h> 
 
int main() 
{  
    int account; 
    char name[ 30 ]; 
    double balance;]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start --><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;stdio.h&gt;<br />
<br />
int main()<br />
{ <br />
&nbsp; &nbsp; int account;<br />
&nbsp; &nbsp; char name[ 30 ];<br />
&nbsp; &nbsp; double balance;<br />
&nbsp; &nbsp; double amount; <br />
&nbsp; &nbsp; FILE *ofPtr;<br />
&nbsp; &nbsp; FILE *tfPtr; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; ofPtr = fopen( &quot;oldmast.dat&quot;, &quot;w&quot; ); <br />
&nbsp; &nbsp; tfPtr = fopen( &quot;trans.dat&quot;, &quot;w&quot; );<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; printf( &quot;Sample data for file oldmast.dat:\n&quot; );<br />
&nbsp; &nbsp; printf( &quot;Enter account, name, and balance (EOF to end): &quot; );<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; while ( scanf( &quot;%d%[^0-9-]%lf&quot;, &amp;account, name, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &amp;balance ) != EOF ) { <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf( ofPtr, &quot;%d %s %.2f\n&quot;, account, name, balance );<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Enter account, name, and balance (EOF to end): &quot; );<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; fclose( ofPtr );<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; printf( &quot;\nSample data for file trans.dat:\n&quot; );<br />
&nbsp; &nbsp; printf( &quot;Enter account and transaction amount (EOF to end): &quot; );<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; while ( scanf( &quot;%d%lf&quot;, &amp;account, &amp;amount ) != EOF ) { <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf( tfPtr, &quot;%d %.2f\n&quot;, account, amount );<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Enter account and transaction amount (EOF to end): &quot; );<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; fclose( tfPtr );<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; return 0;<br />
}</code><hr />
</div>keeps looping whenever i input EOF<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>akira124xd</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156906-need-help-keeps-looping.html</guid>
		</item>
		<item>
			<title>Having problem with ADC display on PIC18F4520 LCD</title>
			<link>http://cboard.cprogramming.com/c-programming/156905-having-problem-adc-display-pic18f4520-lcd.html</link>
			<pubDate>Tue, 21 May 2013 05:04:44 GMT</pubDate>
			<description><![CDATA[Hi, I'm having some problems on interfacing ADC with LCD display. The main purpose of using ADC is because I need to read the voltage of the batteries and transfer it, and display to LCD. I'm using MCC18 compiler. Please guide or help me! 
 
 
Code: 
--------- 
include <p18f4520.h> 
#include...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi, I'm having some problems on interfacing ADC with LCD display. The main purpose of using ADC is because I need to read the voltage of the batteries and transfer it, and display to LCD. I'm using MCC18 compiler. Please guide or help me!<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">include &lt;p18f4520.h&gt;<br />
#include &lt;delays.h&gt;<br />
#include &lt;stdlib.h&gt; <br />
<br />
<br />
void Init_LCD(void);&nbsp; &nbsp; //Initialise the LCD<br />
void W_ctr_8bit(char);&nbsp; //8-bit Control word for LCD<br />
void W_data_8bit(char); //8-bit Text Data for LCD<br />
<br />
<br />
ADCON0=0b00000001;&nbsp; &nbsp; <br />
ADCON0bits.GO = 1;&nbsp; &nbsp; &nbsp; &nbsp; // Start ADC <br />
Delay10TCYx(5); //give channel time to initiliase <br />
while(ADCON0bits.DONE); // Wait for conversion to finish. <br />
counts=ADRESH*255 +ADRESL; <br />
//for 3.62 volts, expect a count of 741 <br />
millivolts = (counts * 1.367)/100; //gives a result of 3630.9 <br />
&nbsp; &nbsp; Init_LCD();<br />
&nbsp; &nbsp; W_ctr_8bit(0x80);<br />
&nbsp; &nbsp; for(i=0;i&lt;8;i++)<br />
&nbsp; &nbsp; W_data_8bit(MESS3[i]);<br />
&nbsp; &nbsp; W_ctr_8bit(0x8C);<br />
&nbsp; &nbsp; W_data_8bit('V');<br />
<br />
<br />
itoa(millivolts,Distance1); //(int value, char * str, int base); <br />
<br />
<br />
W_ctr_8bit(0x89);&nbsp; &nbsp; &nbsp; &nbsp; <br />
while(Distance1[i])<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; W_data_8bit(Distance1[i]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; i++;<br />
&nbsp; &nbsp; }</code><hr />
</div><!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>caramelz</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156905-having-problem-adc-display-pic18f4520-lcd.html</guid>
		</item>
		<item>
			<title>Need help Just Keeps looping</title>
			<link>http://cboard.cprogramming.com/c-programming/156904-need-help-just-keeps-looping.html</link>
			<pubDate>Tue, 21 May 2013 04:56:11 GMT</pubDate>
			<description><![CDATA[Code: 
--------- 
#include <stdio.h> 
 
int main() 
{  
	int account; 
	char name[ 30 ]; 
	double balance;]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start --><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;stdio.h&gt;<br />
<br />
int main()<br />
{ <br />
&nbsp; &nbsp; &nbsp; &nbsp; int account;<br />
&nbsp; &nbsp; &nbsp; &nbsp; char name[ 30 ];<br />
&nbsp; &nbsp; &nbsp; &nbsp; double balance;<br />
&nbsp; &nbsp; &nbsp; &nbsp; double amount; <br />
&nbsp; &nbsp; &nbsp; &nbsp; FILE *ofPtr;<br />
&nbsp; &nbsp; &nbsp; &nbsp; FILE *tfPtr; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ofPtr = fopen( &quot;oldmast.dat&quot;, &quot;w&quot; ); <br />
&nbsp; &nbsp; &nbsp; &nbsp; tfPtr = fopen( &quot;trans.dat&quot;, &quot;w&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Sample data for file oldmast.dat:\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Enter account, name, and balance (EOF to end): &quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; while ( scanf( &quot;%d%[^0-9-]%lf&quot;, &amp;account, name, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;balance ) != EOF ) { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fprintf( ofPtr, &quot;%d %s %.2f\n&quot;, account, name, balance );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Enter account, name, and balance (EOF to end): &quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; fclose( ofPtr );<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;\nSample data for file trans.dat:\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Enter account and transaction amount (EOF to end): &quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; while ( scanf( &quot;%d%lf&quot;, &amp;account, &amp;amount ) != EOF ) { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fprintf( tfPtr, &quot;%d %.2f\n&quot;, account, amount );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf( &quot;Enter account and transaction amount (EOF to end): &quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; fclose( tfPtr );<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
}</code><hr />
</div><!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>akira124xd</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156904-need-help-just-keeps-looping.html</guid>
		</item>
		<item>
			<title>Issue with random numbers</title>
			<link>http://cboard.cprogramming.com/c-programming/156903-issue-random-numbers.html</link>
			<pubDate>Tue, 21 May 2013 03:04:06 GMT</pubDate>
			<description><![CDATA[Code: 
--------- 
#include <stdio.h> 
#include <stdlib.h> 
#include <math.h> 
 
int xPosCalc(int sigmaMatter, int muMatter, int sigmaAntimatter, int muAntimatter, int xRand) 
{ 
    xRand = rand() % 36;]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start --><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;math.h&gt;<br />
<br />
int xPosCalc(int sigmaMatter, int muMatter, int sigmaAntimatter, int muAntimatter, int xRand)<br />
{<br />
&nbsp; &nbsp; xRand = rand() % 36;<br />
&nbsp; &nbsp; int xPosMatter = (1/(sigmaMatter*sqrt(2*M_PI)))*exp(-((xRand-muMatter)*(xRand-muMatter))/(2*(sigmaMatter*sigmaMatter)));<br />
&nbsp; &nbsp; int xPosAntimatter = (1/(sigmaAntimatter*sqrt(2*M_PI)))*exp(-((xRand-muAntimatter)*(xRand-muAntimatter))/(2*(sigmaAntimatter*sigmaAntimatter)));<br />
&nbsp; &nbsp; int xProbability = xPosMatter * xPosAntimatter;<br />
&nbsp; &nbsp; printf(&quot;Random variable is: %d&quot;, xRand);<br />
&nbsp; &nbsp; printf(&quot;\nProbability is: %d&quot;, xProbability);<br />
}<br />
<br />
int main(void)<br />
{<br />
&nbsp; &nbsp; int sigmaMatter = 4.2;<br />
&nbsp; &nbsp; int muMatter = 27.0;<br />
&nbsp; &nbsp; int sigmaAntimatter = 6.0;<br />
&nbsp; &nbsp; int muAntimatter = 17.0;<br />
&nbsp; &nbsp; int xRand = 0.0;<br />
&nbsp; &nbsp; xPosCalc(sigmaMatter, muMatter, sigmaAntimatter, muAntimatter, xRand);<br />
}</code><hr />
</div>The problem is my random variable (restricted from 0-35) comes out as 29 every time I run the program, not a random number like I need.  I'm guessing this is either a problem with the way I'm passing my variables (something I'm still learning) or a stack error.<br />
<br />
I know my math can be simplified, but I don't think that is what's causing the current issue.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>Paul Omans</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156903-issue-random-numbers.html</guid>
		</item>
		<item>
			<title>operators in switch statements?</title>
			<link>http://cboard.cprogramming.com/c-programming/156901-operators-switch-statements.html</link>
			<pubDate>Tue, 21 May 2013 00:12:26 GMT</pubDate>
			<description><![CDATA[Hi folks, 
 
So I'm learning about this switch thing.  It seems like a cool, clean alternative to a bunch of if's and else if's.  I have one question though.  In the tutorial on this site concerning switch it says this: 
 
 
---Quote--- 
Switch case statements are a substitute for long if...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi folks,<br />
<br />
So I'm learning about this switch thing.  It seems like a cool, clean alternative to a bunch of if's and else if's.  I have one question though.  In the tutorial on this site concerning switch it says this:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Quote:</div>
	<div class="bbcode_quote printable">
		<hr />
		
			Switch case statements are a substitute for long if statements that compare a variable to several &quot;integral&quot; values (&quot;integral&quot; values are simply values that can be expressed as an integer, such as the value of a char).
			
		<hr />
	</div>
</div>So does that mean switch statements can only test if variable == value and nothing more, like &gt;  &lt;  &gt;=  &lt;=  !=  etc... ?  I tried to make a program to test this and it seems like switch statements are limited to == but I'm not sure, maybe I'm doing something wrong.<br />
<br />
This is the program I tried to make to test this:  <br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;stdio.h&gt;<br />
<br />
int main () {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; int n;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf ( &quot;\nEnter a number to test dis shiet.\n\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; scanf ( &quot;%i&quot;, &amp;n );<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; switch ( n ) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 0:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( &quot;\nYou entered 0.\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; &gt; 0:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( &quot;\nYou entered a number &gt; 0.\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; &lt; 0:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( &quot;\nYou entered a number &lt; 0.\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( &quot;\ndafuq?\n&quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
}</code><hr />
</div>The compiler said this:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Quote:</div>
	<div class="bbcode_quote printable">
		<hr />
		
			switchtest.c: In function 'main':<br />
switchtest.c:22:9: error: expected expression before '&gt;' token<br />
switchtest.c:22:9: error: expected expression before '&gt;' token<br />
switchtest.c:25:9: error: expected expression before '&lt;' token<br />
switchtest.c:25:9: error: expected expression before '&lt;' token
			
		<hr />
	</div>
</div>So is it true that switch statements only work with the built in == operator? :frown: if that was the case then I would feel rather meh about switch statements.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>SCRIPT_KITTEH</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156901-operators-switch-statements.html</guid>
		</item>
		<item>
			<title>Question about FILES</title>
			<link>http://cboard.cprogramming.com/c-programming/156900-question-about-files.html</link>
			<pubDate>Mon, 20 May 2013 23:24:22 GMT</pubDate>
			<description><![CDATA[Hi!!!!I have a question...Why,when I try to run the following code,although I have saved a txt file named "m.txt",I get the message I couldn't open m.txt for writing.?????I hope someone can help me!!!!!Thanks in advance!!!!! 
 
Code: 
--------- 
#include <stdio.h> 
#include <stdlib.h> 
 
 
int...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi!!!!I have a question...Why,when I try to run the following code,although I have saved a txt file named &quot;m.txt&quot;,I get the message I couldn't open m.txt for writing.?????I hope someone can help me!!!!!Thanks in advance!!!!!<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
<br />
<br />
int main()<br />
{<br />
FILE *fp;<br />
int i;<br />
fp = fopen(&quot;m.txt&quot;, &quot;w&quot;);<br />
if (fp == NULL) {<br />
printf(&quot;I couldn't open m.txt for writing.\n&quot;);<br />
exit(0);<br />
}<br />
<br />
<br />
for (i=0; i&lt;=10; ++i)<br />
fprintf(fp, &quot;%d, %d\n&quot;, i, i*i);<br />
<br />
<br />
fclose(fp);<br />
<br />
<br />
return 0;<br />
}</code><hr />
</div><!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>evinda</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156900-question-about-files.html</guid>
		</item>
		<item>
			<title>Doubt reagarding use of const variable</title>
			<link>http://cboard.cprogramming.com/c-programming/156895-doubt-reagarding-use-const-variable.html</link>
			<pubDate>Mon, 20 May 2013 18:14:28 GMT</pubDate>
			<description><![CDATA[Hi please tell me what shud be the result of following piece of code and why?  
 
Code: 
--------- 
#include<..> //Consider all includes correctly 
main() 
{ 
int i; 
const int j; 
int *p, *q;]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi please tell me what shud be the result of following piece of code and why? <br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include&lt;..&gt; //Consider all includes correctly<br />
main()<br />
{<br />
int i;<br />
const int j;<br />
int *p, *q;<br />
*p = i;<br />
*q = j;<br />
*p++;<br />
*q++;<br />
printf(&quot;%d\t%d\t%d\t%d&quot;, *p, *q, i, j);<br />
<br />
}</code><hr />
</div>p.s. - ignore any syntax error. I hope you must have understood the real doubt of mine.<br />
Thanks.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>AbhinavBajpai</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156895-doubt-reagarding-use-const-variable.html</guid>
		</item>
		<item>
			<title>Adding a constant to multiple variables</title>
			<link>http://cboard.cprogramming.com/c-programming/156894-adding-constant-multiple-variables.html</link>
			<pubDate>Mon, 20 May 2013 17:46:11 GMT</pubDate>
			<description>Hi, 
 
I was hoping someone could help me with this problem. 
 
Instead of using: 
 
Code: 
--------- 
x=x+k 
y=y+k</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi,<br />
<br />
I was hoping someone could help me with this problem.<br />
<br />
Instead of using:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">x=x+k<br />
y=y+k<br />
z=z+k</code><hr />
</div>Is there a more elegant method of adding the same constant to many variables?<br />
<br />
Something like:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">(x, y, z) = (x, y, z) + k&nbsp; ??</code><hr />
</div>I tried searching for a solution but couldn't find what I was looking for.<br />
<br />
Thanks for any help<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>melia789</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156894-adding-constant-multiple-variables.html</guid>
		</item>
		<item>
			<title>Makefile for a single file</title>
			<link>http://cboard.cprogramming.com/c-programming/156893-makefile-single-file.html</link>
			<pubDate>Mon, 20 May 2013 13:04:26 GMT</pubDate>
			<description><![CDATA[Hi, 
 
I'm trying to create a Makefile for a single fie ( mycod.c) 
Could you please help me with the syntax? 
 
thanks]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi,<br />
<br />
I'm trying to create a Makefile for a single fie ( mycod.c)<br />
Could you please help me with the syntax?<br />
<br />
thanks<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>ilans11il</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156893-makefile-single-file.html</guid>
		</item>
		<item>
			<title>Vectorization</title>
			<link>http://cboard.cprogramming.com/c-programming/156890-vectorization.html</link>
			<pubDate>Mon, 20 May 2013 10:11:46 GMT</pubDate>
			<description><![CDATA[I'm trying to learn how o implement vectorization. Please help me with a hello world kind of thing... 
 
Lets say I have this an array like this. 
 
Code: 
--------- 
int Array[10] = { 3,4,5,3,4,5,6,7,8,9}; 
--------- 
If I traverse through the array and preform some simple calculation like adding...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->I'm trying to learn how o implement vectorization. Please help me with a hello world kind of thing...<br />
<br />
Lets say I have this an array like this.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">int Array[10] = { 3,4,5,3,4,5,6,7,8,9};</code><hr />
</div>If I traverse through the array and preform some simple calculation like adding numbers, how would I go about vectorizing this feat? For example if I want to add numbers, .<br />
<br />
An example, add element at index 5,6,7 to element with index 1.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">0 1 2 3 4 5 6 7 8 9 --- index<br />
3,4,5,2,8,2,3,5,1,2 --- ints</code><hr />
</div>Thanks!<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/c-programming/">C Programming</category>
			<dc:creator>überfuzz</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/c-programming/156890-vectorization.html</guid>
		</item>
	</channel>
</rss>
