🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #1174

Some C problems

#1174
From: Gregary John Boyles
Date: Wed, 10 Jan 1996 13:40
85 lines
4187 bytes
PROBLEM 1.
void WriteInFileToOutFile(FILE *InFile,FILE *OutFile,char *InFileName,char *OutFileName,long NumBytes,byte DiskNum)
{
     const word Size=1;
     const word MaxBytes=65535; Produces warning : conversion may lose 
                                significant bits. Why? 65535 is within the
                                range for a word (unsigned int)

     word NumRead,NumWritten;
     long Index;
     void *BufferPtr;

     /* Write the disk number to the first byte of the file. */
     fwrite(&DiskNum,Size,1,OutFile);
     BufferPtr=(void *)malloc(MaxBytes);
     Index=0;
     while (Index<=NumBytes)
     {


Am I using fread and fwrite correctly or do I need to dereference bufferptr 
when I pass it to these procedures because I am finding that NumRead 
(number of bytes read) != NumWritten (number of bytes written - 0).

******************************************************************************
*                                                                            *
*         NumRead=(fread(BufferPtr,Size,MaxBytes,InFile))*Size;              *
*         if (NumRead==0)                                                    *
*         {                                                                  *
*              strcpy(ErrorMessage,"An error occured while reading from infil*
*              strcat(ErrorMessage,InFileName);                              *
*              strcat(ErrorMessage," - please make sure that this file is not*
*              Error(ErrorMessage);                                          *
*              fclose(OutFile);                                              *
*              fclose(InFile);                                               *
*              exit(1);                                                      *
*         }                                                                  *
*         NumWritten=(fwrite(BufferPtr,Size,NumRead,OutFile))*Size;          *
*         if (NumWritten!=NumRead)                                           *
*         {                                                                  *
*              strcpy(ErrorMessage,"An error occured while writing to outfile*
*              strcat(ErrorMessage,OutFileName);                             *
*              strcat(ErrorMessage," - number of bytes read does not equal th*
*              Error(ErrorMessage);                                          *
*              fclose(OutFile);                                              *
*              fclose(InFile);                                               *
*              exit(1);                                                      *
*         }                                                                  *
******************************************************************************

          Index+=NumRead;
     }
}



With this statement DiskInfo.df_total*DiskInfo.df_sclus*DiskInfo.df_bsec calculated
using my calculator produces the correct drive capacity i.e. 360K however
DriveSize does not contain the correct value i.e. 32000 instead of 360000 (approximate).
Why is this happening? The above fields are of type unsigned.

PROBLEM 2.
long DriveSize;
struct dfree DiskInfo;
.
.
.

getdfree(DriveNum,&DiskInfo);
DriveSize=DiskInfo.df_total*DiskInfo.df_sclus*DiskInfo.df_bsec;

df_total:clusters
df_sclus:sectors/cluster
df_bsec:bytes/sector


PROBLEM 3.
When I want to output a long int type varaible with printf, it prints out
a garbage value for the variable despite declaring it as a li/ld in the
format string. What am I doing wrong?

PROBLEM 4.
How do you use literal constants bigger than words e.g. how would you use
the literal constant 1000000 without getting the 'constant out of range'
warning/error?
Technical Details
Message-ID: <4d0fjj$eok@lugb.latrobe.edu.au>
Path: arc1-ca.pugleaf.net!lugb.latrobe.edu.au!lux!cs102238

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lugb.latrobe.edu.au!lux!cs102238
From: cs102238@lux.latrobe.edu.au (Gregary John Boyles )
Newsgroups: alt.msdos.programmer,comp.lang.c
Subject: Some C problems
Date: 10 Jan 1996 13:40:03 GMT
Organization: La Trobe University
Distribution: world
Message-ID: <4d0fjj$eok@lugb.latrobe.edu.au>
NNTP-Posting-Host: lux.latrobe.edu.au