Skip to content

Commit 5084cdd

Browse files
committed
Fixed random char at the beginning of the string
1 parent 2f4d4ee commit 5084cdd

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.o
2+
numstr_*
23
numstr
34
.vscode
45
*.exe
6+
*.gz

main.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ int load_lang(const char *file_name)
3737
int index = 0;
3838
sscanf(buffer, "%s %i = \"%[^\"]", var_name, &index, value);
3939
if (strcmp(var_name, "zero") == 0)
40-
sprintf(digits.zero, "%s", value);
40+
sprintf(digits.zero, "%s-", value);
4141
else if (strcmp(var_name, "ones") == 0)
4242
{
4343
digits.ones[index] = malloc(strlen(value));
44-
sprintf(digits.ones[index], "%s ", value);
44+
sprintf(digits.ones[index], "%s-", value);
4545
}
4646
else if (strcmp(var_name, "tens") == 0)
4747
{
4848
digits.tens[index] = malloc(strlen(value));
49-
sprintf(digits.tens[index], "%s ", value);
49+
sprintf(digits.tens[index], "%s-", value);
5050
}
5151
else if (strcmp(var_name, "hundreds") == 0)
5252
{
5353
digits.hundreds[index] = malloc(strlen(value));
54-
sprintf(digits.hundreds[index], "%s ", value);
54+
sprintf(digits.hundreds[index], "%s-", value);
5555
}
5656
else if (strcmp(var_name, "out_range_err") == 0)
5757
{
@@ -77,6 +77,7 @@ int load_lang(const char *file_name)
7777
char *digit_to_word(int num, char *plus_str)
7878
{
7979
char *str = malloc(2048);
80+
sprintf(str, "\b"); // without this line the output will have some random characters in the beginning and I don't know why
8081
if (num > 19)
8182
{
8283
strcat(str, digits.tens[num / 10]);
@@ -92,7 +93,7 @@ char *digit_to_word(int num, char *plus_str)
9293
char *num_to_word(long int num)
9394
{
9495
char *str = malloc(2048);
95-
sprintf(str, ""); // without this line the output will have some random characters in the beginning and I don't know why
96+
sprintf(str, "\b"); // without this line the output will have some random characters in the beginning and I don't know why
9697

9798
if (num == 0)
9899
{
@@ -130,6 +131,7 @@ char *num_to_word(long int num)
130131
else if ((num / 100) % 10)
131132
strcat(str, digit_to_word(((num / 100) % 10), digits.hundreds[4]));
132133
strcat(str, digit_to_word((num % 100), ""));
134+
str[strlen(str) - 1] = 0;
133135

134136
return str;
135137
}
@@ -151,7 +153,7 @@ int main(int argc, char **argv)
151153
fscanf(stdin, "%s", user_input);
152154
if (sscanf(user_input, "%li", &num) == 0)
153155
{
154-
fprintf(stderr, "%s\"%s\" %s", UI.nan_err[0], user_input, UI.nan_err[1]);
156+
fprintf(stderr, "%s\"%s\" %s\n", UI.nan_err[0], user_input, UI.nan_err[1]);
155157
return -1;
156158
}
157159
if (num > 1109999999)

makefile

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
CC = gcc
22
CFLAGS = -O3
33
LDFLAGS =
4+
NAME = numstr
5+
RELEASE_TAG = 0.0
46

57
.PHONY: main
68

79
build: main
8-
$(CC) $(CFLAGS) $(LDFLAGS) *.o -o numstr
10+
$(CC) $(CFLAGS) $(LDFLAGS) *.o -o $(NAME)
911

1012
main:
1113
$(CC) $(CFLAGS) -c main.c
1214

1315
run: main
14-
./numstr
16+
./$(NAME)
1517

1618
clean:
17-
rm *.o numstr
19+
rm -r *.o $(NAME) $(NAME)_* *.exe
1820

1921
debug_build: CFLAGS = -Wall -Wextra -g
2022
debug_build: build
2123

22-
debug_run: debug_build run
24+
debug_run: debug_build run
25+
26+
linux_release: build
27+
mkdir $(NAME)_$(RELEASE_TAG)-linux
28+
cp -rt $(NAME)_$(RELEASE_TAG)-linux $(NAME) ./langs/
29+
tar -zcvf $(NAME)_$(RELEASE_TAG)-linux.tar.gz $(NAME)_$(RELEASE_TAG)-linux
30+
31+
windows_release: CC=x86_64-w64-mingw32-gcc
32+
windows_release: build
33+
mkdir $(NAME)_$(RELEASE_TAG)-win64
34+
cp -rt $(NAME)_$(RELEASE_TAG)-win64 $(NAME).exe ./langs/
35+
zip -9r $(NAME)_$(RELEASE_TAG)-win64.zip $(NAME)_$(RELEASE_TAG)-win64

0 commit comments

Comments
 (0)