Guest User

Untitled

a guest
Jun 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.     $firstName = "";
  3.     $lastName = "";
  4.     $age = 0;
  5.     $yearsUntilOneHundred = 0;
  6.     $recordCount = 0;
  7.     $msg = "";
  8.    
  9.     //Opens the file or kills the app
  10.     $fin = fopen("names.txt","r") or die("cannot open names.txt");
  11.    
  12.     fprintf($fout,"\n              SALES REPORT\n");
  13.     fprintf($fout,"\n     First       Last       Years till 100\n");
  14.  
  15.     $fout = fopen("report.txt","w") or die("cannot open names.txt");
  16.        
  17.     //Read the first record
  18.     fscanf($fin, "%s%s%d,$firstName, $lastName, $age");
  19.     while( !feof($fin))
  20.    
  21.     {
  22.         //processing
  23.         if ($age >= 90)
  24.         {
  25.             $msg="Older than dirt";
  26.         }
  27.             else
  28.             {
  29.                 $msg = "Just a kid!";
  30.             }
  31.         $recordCount = $recordCount + 1;
  32.         $yearsUntilOneHundred = 100-$age;
  33.         fprintf($fout,"\n%-10s%-10s%12d %-17s",
  34.             $firstName, $lastName, $yearsUntilOneHundred, $msg);
  35.            
  36.         //Read next record
  37.         fscanf($fin,"%s%s%d", $firstName, $lastName, $age);
  38.     }
  39.     fprintf($fout,"\nRecord Count is %d", $recordCount);
  40.     fclose ($fin); 
  41.     fclose ($fout);
  42.  
  43.     //fscanf(STDIN, "%s", $buster);
  44.  
  45. ?>
Add Comment
Please, Sign In to add comment