Skip to content

Commit 3df5527

Browse files
committed
uploaded file
1 parent 8d82aa7 commit 3df5527

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

ipConversion.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
11
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <math.h>
25
#define MAX 16
6+
7+
8+
int* splitIp(char* ip)
9+
{
10+
int i, j, *arr;
11+
int temp =0;
12+
arr = (int*)malloc( 4* sizeof(int));
13+
14+
for(i=0, j=0; i<strlen(ip); i++){
15+
if(ip[i] == '.'){
16+
arr[j] = temp;
17+
temp = 0;
18+
j++;
19+
}
20+
else{
21+
temp = temp*10 + (ip[i] - 48);
22+
}
23+
}
24+
25+
arr[j] = temp;
26+
27+
return arr;
28+
}
29+
30+
331
int main()
432
{
33+
int i;
534
char ip[MAX];
6-
scanf("%s", )
7-
}
35+
unsigned int res = 0;
36+
scanf("%s", ip);
37+
38+
int *arr = splitIp(ip);
39+
40+
unsigned int a = arr[0] * pow(2, 24);
41+
unsigned int b = arr[1] * pow(2, 16);
42+
unsigned int c = arr[2] * pow(2, 8);
43+
unsigned int d = arr[3] * pow(2, 0);
44+
45+
res = a + b + c + d;
46+
47+
printf("Result = %u", res);
48+
49+
return 0;
50+
}
51+
52+

0 commit comments

Comments
 (0)