I'm new to C programming and have been reading about it here.
I found out that int
data types can be used to declare variables for a number/integer with value range between -32,768 to 32,767
or -2,147,483,648 to 2,147,483,647
.
While char
data types can be used to store -128 to 127 or 0 to 255
value.
What about an IP Address? I've tried int
however only first octet of the IP is recognized.
It also doesn't work well with char
.
Codes
C:\Codes>more input_output.c
#include <stdio.h>
int main()
{
int a;
int b;
char c;
printf("\n1. Enter a number : ");
scanf("%d",&a);
printf("You've entered %d\n",a);
printf("\n2. Enter an IP Address : ");
scanf("%d",&b);
printf("You've entered %d\n",b);
printf("\n3. Enter an IP Address : ");
scanf("%c",&c);
printf("You've entered %d\n",c);
return 0;
}
C:\Codes>
Compiling
C:\Codes>gcc input_output.c -o input_output
C:\Codes>
Final Output
C:\Codes>input_output.exe
1. Enter a number : 5
You've entered 5
2. Enter an IP Address : 8.8.8.8
You've entered 8
3. Enter an IP Address : You've entered 46
C:\Codes>