#include <stdio.h>
void fillline(char *line, char c, int len){
for(int i = 0; i<len-1; i++)
line[i] = c;
line[len-1] = '\n';
line[len] = '\0';
}
int main() {
char xs[4][30];
fillline(xs[0], '-', 30);
fillline(xs[1], '(', 30);
fillline(xs[2], ')', 30);
fillline(xs[3], 'Z', 30);
printf("%s", xs[0]);
printf("%s", xs[1]);
printf("%s", xs[2]);
printf("%s", xs[3]);
}
Hello, C-programming newbie here. I have a problem with the code above. I expect
-----------------------------
(((((((((((((((((((((((((((((
)))))))))))))))))))))))))))))
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
as command-line output generated from my code, but I get
-----------------------------
(((((((((((((((((((((((((((((
)))))))))))))))))))))))))))))
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
(((((((((((((((((((((((((((((
)))))))))))))))))))))))))))))
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
)))))))))))))))))))))))))))))
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
What am I doing wrong? I tried fflush(stdout)
and setbuf(stdout, NULL)
(although I am definitely not sure that this is a stdout
-problem).
Thank you in advance.