Q:

An engineering corporation has a data file “vendorcust.dat” which has names of its vendors and customers for various products, along with a title line

0

An engineering corporation has a data file “vendorcust.dat” which 

has names of its vendors and customers for various products, along 

with a title line. The format is that every line has the vendor name and

then the customer name, separated by one space. For example, it 

might look like this (although you cannot assume the length):

>> type vendorcust.dat

Vendor Customer

Acme XYZ

Tulip2you Flowers4me

Flowers4me Acme

XYZ Cartesian

The “Acme” company wants a little more zing in their name, however, 

so they’ve changed it to “Zowie”; now this data file has to be modified.

Write a script that will read in from the “vendorcust.dat” file and 

replace all occurrences of “Acme” with “Zowie”, writing this to a new 

file called “newvc.dat”. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch9Ex29.m

fidin = fopen('vendorcust.dat');

fidout = fopen('newvc.dat','w');

while ~feof(fidin)

 aline = fgetl(fidin);

 newline = strrep(aline,'Acme','Zowie');

 fprintf(fidout,'%s\n',newline);

end

fclose('all');

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now