/
Homework 08 Due date: Nov 30, 2016 Homework 08 Due date: Nov 30, 2016

Homework 08 Due date: Nov 30, 2016 - PowerPoint Presentation

myesha-ticknor
myesha-ticknor . @myesha-ticknor
Follow
364 views
Uploaded On 2018-03-21

Homework 08 Due date: Nov 30, 2016 - PPT Presentation

CSC215 Homework int account amount char company25 We want to write some information to the file paymentsdat fptr fopenpaymentsdat r to write mode should be w not r ID: 660117

file dat fopen write dat file write fopen statement accountnum record currentbalance fptr amount account amp open ofptr nfptr

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Homework 08 Due date: Nov 30, 2016" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Homework 08

Due date: Nov 30, 2016

CSC215

HomeworkSlide2

int account, amount;

char company[25];

We want to write some information to the file "payments.dat":

fptr = fopen("payments.dat", "r"); /* to write, mode should be “w”, not “r” */printf(fptr, "%d%s%d\n", account, company, amount);open("receive.dat", "r+"); /* open is not part of the standard library, use fopen */fptr = fopen("payments.dat", "r");scanf(fptr, "%d%s%d\n", account, company, amount);/* pass arguments account and amount by address */We want to open the file "tools.dat" and add some data:if ((fptr = fopen("tools.dat", "w+"))){ /* statements */ }/* adding means append, use mode “a” instead of “w+” */

Question 1

: Find the error in each of the following program segments, and show how to correct it.Slide3

Question 2

: Write a single statement to accomplish each of the following. Assume the statements apply to the same program.

int

accountNum; float currentBalance, dollarAmount; char name[50];Write a statement that opens the file "oldmast.dat" for reading and assigns the returned file pointer to ofPtr.FILE* ofPtr = fopen("oldmast.dat", "r");Write a statement that opens the file "trans.dat" for reading and assigns the returned file pointer to tfPtr.FILE* tfPtr = fopen("trans.dat", "r");Write a statement that opens the file "newmast.dat" for writing (and creation) and assigns the returned file pointer to nfPtr. FILE* nfPtr = fopen("newmast.dat", "w");Write a statement that reads a record from the file "oldmast.dat". The record consists of integer accountNum, string name and floating-point currentBalance. fscanf(ofPtr, "%d%s%f", &accountNum, name, &currentBalance);Write a statement that reads a record from the file "trans.dat". The record consists of the integer accountNum and floating-point dollarAmount.fscanf(tfPtr, "%d%s%f", &accountNum, &dollarAmount);

Write a statement that writes a record to the file "newmast.dat". The record consists of the integer accountNum, string name and floating-point currentBalance.

fprintf(nfPtr, "%d%s%f", accountNum, name, currentBalance);