View Full Version : Quick (and basic) ANSI C Question
IronManX
02-26-2002, 12:50 PM
How do I do this?<br /><br />I have a stored value in an int variable. I want to scan a new value and add that to the stored variable without creating a new variable.<br /><br />How do I do this?<br /><br />Homework is due LOL.<br /><br />thanx
Brian911
02-26-2002, 01:55 PM
is ANSI C "cin << " and stuff like that?<br /><br />lol I had some basic C++ knowledge 3 years ago, almost forgot everything <img border="0" title="" alt="[Wink]" src="wink.gif" />
keyman
02-26-2002, 10:06 PM
</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: fixed;">char in_buffer[41];<br />int var1,var2;<br /><br />/* get input from the user */<br />fgets(in_buffer,40,stdin);<br />var1 = atoi(in_buffer);<br />fgets(in_buffer,40,stdin);<br />var2 = atoi(in_buffer);<br /><br />var1+=var2; /* or var1 = var1 + var2; */<br />printf("Total: %d\n",var1);</pre><hr /></blockquote><font size="2" face="Verdana, Arial">ps, don't use scanf() for input.. use fgets() then convert the buffer to int using atoi().<br />Its quite easy to leave buffer overflow exploits using scanf().<br /><br /> <img border="0" alt="[Bounce]" title="" src="graemlins/bounce.gif" />
IronManX
02-26-2002, 10:14 PM
Thanks keyman!
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.