Sponsored Content
Full Discussion: Feof
Top Forums Programming Feof Post 11405 by primal on Tuesday 4th of December 2001 07:27:38 PM
Old 12-04-2001
Question Feof

Hi Everyone,
I'm having problems with feof
I've storing my variables inside a file, and then in another program, opening that file and recalling the information.
The problem im having is that it's repeating the last set of entries in my while loop.
(if i have one set of product no., quantity, and price in my file, it repeats it twice. if i have two sets or more in my file, it repeats the last set twice)
I think it has something to do with how i have my while(!feof(file)) set up.
Does anyone know what's going on?
Code:
#include[stdio.h]
FILE *invfile;
int prod, qty;
float price;

void main()
    {
     invfile = fopen("file.dat","r");
     while(!feof(invfile))
       {
       fscanf(invfile,"%d %d %f", &prod, &qty, &price);
       printf("Product No.     = %d\n",prod);
       printf("Quantity        = %d\n",qty); 
       printf("Price           = %.2f\n\n",price);
       }
     fclose(invfile);
    }

Thanks!
primal
 
SQLSRV_CANCEL(3)														  SQLSRV_CANCEL(3)

sqlsrv_cancel - Cancels a statement

SYNOPSIS
bool sqlsrv_cancel (resource $stmt) DESCRIPTION
Cancels a statement. Any results associated with the statement that have not been consumed are deleted. After sqlsrv_cancel(3) has been called, the specified statement can be re-executed if it was created with sqlsrv_prepare(3). Calling sqlsrv_cancel(3) is not necessary if all the results associated with the statement have been consumed. PARAMETERS
o $stmt - The statement resource to be cancelled. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 sqlsrv_cancel(3) example <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT Sales FROM Table_1"; $stmt = sqlsrv_prepare( $conn, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } if( sqlsrv_execute( $stmt ) === false) { die( print_r( sqlsrv_errors(), true)); } $salesTotal = 0; $count = 0; while( ($row = sqlsrv_fetch_array( $stmt)) && $salesTotal <=100000) { $qty = $row[0]; $price = $row[1]; $salesTotal += ( $price * $qty); $count++; } echo "$count sales accounted for the first $$salesTotal in revenue.<br />"; // Cancel the pending results. The statement can be reused. sqlsrv_cancel( $stmt); ?> NOTES
The main difference between sqlsrv_cancel(3) and sqlsrv_free_stmt(3) is that a statement resource cancelled with sqlsrv_cancel(3) can be re-executed if it was created with sqlsrv_prepare(3). A statement resource cancelled with sqlsrv_free_statement(3) cannot be re-executed. SEE ALSO
sqlsrv_free_stmt(3), sqlsrv_prepare(3). PHP Documentation Group SQLSRV_CANCEL(3)
All times are GMT -4. The time now is 11:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy