Re: Help a newbie :) (prob with 'for')
- From: Tauno Voipio <tauno.voipio@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 08 Feb 2006 21:55:44 GMT
metaltama@xxxxxxxxx wrote:
Hi there,
Ive been using Linux for a couple of years now and getting bored, i
decided to try and learn C. I got this idea while trying to write a
config utility in bash script using grep, sed, dialog, etc. The config
utility is aimed to help simplify the setup of a bridged transparent
proxy. This is my first C program ever, so there's still a lot of
things that i need to learn.
Neyway, to the point...
I'm writing the part where the bridge will be configured then a config
file will be written. My program comes up and on main() it shows a
menu. When 1 is selected scanf ("%d", Selection) - Selection is
declared - it goes to a fuction Configure_Bridge().
There you are asked the bridge name, IP, subnet, etc. The problem is
with the number of NICS. I tried to create a 'for loop' for the program
to know what NICS to 'ifconfig ethX 0.0.0.0' in the bridge script the
program would write. But the for doesn't work like it should...
Here's a snippet of what i want to do (Instead of appending data to the
script, there's still just a printf(Enabled eth%d", EthNr); to test it.
But it doesn't work.
----------------------------
int Nr_NICs;
int EthNr;
Configure Birdge()
{
printf ("Enter number of NICs : ");
scanf ("%d", &NrNICs);
for (EthNr = 0; EthNr <= NrNICS; EthNr++)
{
printf "Enabled eth%d", EthNr);
}
}
----------------------------
The output of this is when 5 is keyed in a scanf("%d", &NrNICs); :
Enabled eth0
Thats it. It doesn't look as if it's doing much looping over there...
Can someone point out my error plz. It's prob something stupid, but plz
help. Thanx
Constant Meiring
It seems that you have not copied the snippet from the source
you have compiled.
It does not compile:
- there are three different ways of writing 'NrNICS',
- there is a parenthesis missing after 'printf'.
After the corrections, it does print five results, but on
a single line: there is no separator after the format in printf
(maybe a '\n' missing).
Next time, please copy the snippet from the real source.
--
Tauno Voipio
tauno voipio (at) iki fi
.
- References:
- Help a newbie :) (prob with 'for')
- From: metaltama
- Help a newbie :) (prob with 'for')
- Prev by Date: Re: detecting file types
- Next by Date: Re: detecting file types
- Previous by thread: Help a newbie :) (prob with 'for')
- Next by thread: Re: Help a newbie :) (prob with 'for')
- Index(es):
Relevant Pages
|
Loading