I read the name of a file from input and i want to sort the content and the sorted content must be added in file. But i get only this output:
Start End
function main(){
global $argc, $argv;
if($argc == 1){
print("Please provide text file path");
return;
}
print("START\n");
run($argv[1]);
print("END\n");
}
function run($file_name){
$br = fopen($file_name,"r");
$bw = fopen($file_name,"a");
if($br && $bw){
while(($line = fgets($br))!==false){
if($line == "\n" || $line == "") break;
$values = preg_split('/\s+/', $line);
$res = array();
for($i=0; $i< count($values)-1;$i++){
$res[]=(int)$values[$i];
}
fwrite($bw,to_string(insert($res))."\n");
}
}
fclose($br);
fclose($bw);
}
"Insert" is the insertion sort function: fwrite($bw,to_string(insert($res))."\n"); that i call.