PDA

View Full Version : help guysTurbo C



bernie123
March 3rd, 2007, 08:18 PM
guys can u help me? iwant toget the borrowbits, subnet to borrow bits i can'tcovert it
can i know whats the problem?? ill use while but it didnt work T_T
i dont know why, but my mind gonna explode can u tell me whatswrong?? thanks

#include<stdio.h>
#include<conio.h>

main()
{
int a,b,c,d,e,f,sn,bb;
clrscr();
printf("Enter 1st octet :");
scanf("%d",&a);
printf("Enter 2nd octet :");
scanf("%d",&b);
printf("Enter 3rd octet :");
scanf("%d",&c);
printf("Enter 4th octet :");
scanf("%d",&d);

printf("Enter Subnet Mask :");
scanf("%d",&sn);
printf("IP Address : %d %d %d %d",a,b,c,d);

if(a<=126)
{

printf("\nClass A Ip Address");
printf("\nLeading Bits: 0");
printf("\nNumber of Networks : 126");
printf("\nNumber of Host per Network: 16,777,214");
printf("\nDefault Subnet Mask : 255.0.0.0");
}
else if(a>=128 && a<=191)
{
printf("\nClass B Ip Address");
printf("\nLeading Bits: 10");
printf("\nNumber of Networks: 16,384");
printf("\nNumber of Host per Network: 65,535");
printf("\nDefault Subnet Mask : 255.255.0.0");
}
else if(a>=192 && a<=223)
{
printf("\nClass C ip Address");
printf("\nLeading Bits:110");
printf("\nNumberof Networks: 2,097,152");
printf("\nNumber of Host per Network: 254");
printf("\nDeafault Subnet Mask : 255.255.255.0");
}
while(e<sn)
e=e*2;
e++;


printf("subnetting:");

printf("borrowed Bits: %d",bb);


getch();
return 0;
}

MTsoul
March 4th, 2007, 12:48 AM
1. In your while loop, you have not initialized e. It would be any value (probably 0). You wouldn't get what you want.
2. You didn't initialize bb when you printf'ed it. What is bb supposed to be?

TheCanadian
March 4th, 2007, 01:58 AM
I'm no C coder, but I think that multiple statements in a while loop would need to be enclosed in a statement block (braces). Unless of course the incrementation of e is supposed to occur after the while loop, then never mind.