Edit : I understand the confusion. But I am not trying to optimize here, as @sergio said, I could not come up with a better word.
—
I have been writing code in JavaScript and PHP for a long time now, that I find it hard sometimes to optimize my code in C.
What I mean by optimizing is writing a program in less code. here is an example:
int i;
srand(time(NULL));
for(i = 0; i < 10; i++){
printf(" %d ", rand() % 300);
if(i < 10 - 1){
printf("|");
}
}
in Javascript I would have wrote it this way :
var html = ''
for(var i = 0; i < 10; i++){
html += ' '+Math.floor(Math.random() * 100)+' '+( i == 9 ? '|' : '' )
}
the difference in C is that I had to do the If in an other line, and could not act inline on the string. I hope you get my point.
So how would you write my code?
Thank you.
“Number of lines” is traditionally a poor judge of code, if you cram too much into one line it gets unreadable.