Ho il seguente programma:
#include <stdio.h>
int main(){
printf("Ok");
system("echo heilà!");
}
Tutto ok, solamente per il fatto che il programma esegue prima la system() che la printf()... come mai ?
Moderatore: Staff





SIV ha scritto:Ragazzi chi mi spiega perchè avviene ciò?

It's probably like that because of efficiency and because if you have multiple programs writing to a single TTY, this way you don't get characters on a line interlaced. So if program A and B are outputting, you'll usually get:
program A output
program B output
program B output
program A output
program B output
This stinks, but it's better than
proprogrgraam m AB ououtputputt
prproogrgram amB A ououtputtput
program B output
Note that it isn't even guaranteed to flush on a newline, so you should flush explicitly if flushing matters to you.
#include<stdio.h>
int main()
{
printf("Hello World!");
system("echo Ciao Mondo");
return 0;
}


Note: Microsoft runtime libraries do not support line buffering, so printf("will print immediatelly to terminal"):
http://msdn.microsoft.com/en-us/library/86cebhfs.aspx



Visitano il forum: Google [Bot] e 1 ospite