In this code:
int length = atoi(argv[1]);
char *tab = malloc(length * sizeof(char));
memset(tab, '-', length);
puts(tab);
no matter what value I passing to argv[1]
, the output is correct. For example, for argv[1] = "5"
i get -----
(five hyphens).
I'm wondering how puts()
can find the end of input string when I have not put a '\0' at the end of my array of char
s.