-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain3.c
More file actions
46 lines (39 loc) · 860 Bytes
/
Copy pathmain3.c
File metadata and controls
46 lines (39 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "queue2.h"
#include "md5.h"
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
#include<sys/wait.h>
char * parseInt(int num) {
int numArray[4];
char *toRet = malloc(sizeof(char) *5);
int current = 3;
while (current != 0){
if (num != 0) {
numArray[current] = num % 10;
num /=10;
} else {
numArray[current] = 0;
}
current-= 1;
}
for (int i = 0 ; i < 4 ; i++)
toRet[i] = (numArray[i] + '0');
toRet[4] = '\0';
return toRet;
}
int parseChar(char * str) {
int num = 0;
int exp = 1000;
for (int i = 0 ; i < 4 ; i++) {
num += (str[i] - '0') * exp;
exp /= 10;
}
return num;
}
int main() {
printf("%s\n", parseInt(4));
printf("%d\n", parseChar("0005"));
}