Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
carriage return at end of file using fprintf???

Subject: carriage return at end of file using fprintf???

From: Jonathan

Date: 1 Jun, 2011 18:00:21

Message: 1 of 7

Is there a way to include a carriage return (i'm assuming its a carriage return) at the end of a file using fprintf. The end of the file needs to have the following...

    4.60 80.00 3.0
    4.60 100.00 2.0
    5.10 90.00 1.0
    4.10 100.00 30.0
    5.10 90.00 1.0
    4.60 90.00 1.0


In my text editor it looks like a right-hand arrow, in wordpad it's depicted by a square.

Any help would be great.

Thanks
Jon

Subject: carriage return at end of file using fprintf???

From: dpb

Date: 1 Jun, 2011 18:12:00

Message: 2 of 7

On 6/1/2011 1:00 PM, Jonathan wrote:
> Is there a way to include a carriage return...

It's called "newline" and what character(s) it is is platform dependent.

doc fopen % Note the discussion on the 't' option for text files
doc fprintf

--

Subject: carriage return at end of file using fprintf???

From: ImageAnalyst

Date: 1 Jun, 2011 19:50:15

Message: 3 of 7

Are you sure it's not an EOF character instead of a line feed or
carriage return?

Subject: carriage return at end of file using fprintf???

From: Jonathan

Date: 1 Jun, 2011 20:14:05

Message: 4 of 7

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <54d653b9-c969-4075-999b-050bb48221a8@w21g2000yqm.googlegroups.com>...
> Are you sure it's not an EOF character instead of a line feed or
> carriage return?

It's a single 'character" that needs to exist at the end of the file. I am assuming it is an EOF character, but it's not clear how to generate it automatically using fprintf.

Thanks
Jon

Subject: carriage return at end of file using fprintf???

From: dpb

Date: 1 Jun, 2011 20:46:44

Message: 5 of 7

On 6/1/2011 3:14 PM, Jonathan wrote:
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> <54d653b9-c969-4075-999b-050bb48221a8@w21g2000yqm.googlegroups.com>...
>> Are you sure it's not an EOF character instead of a line feed or
>> carriage return?
>
> It's a single 'character" that needs to exist at the end of the file. I
> am assuming it is an EOF character, but it's not clear how to generate
> it automatically using fprintf.
...

Oh, I got (apparently) sidetracked by assuming the title had something
to do w/ the subject...silly me! :)

First things first --

a) why does the existence of a special character at the file matter? In
general this "feature" has gone the was of the dodo.

b) if, for some reason, it is important, first thing to do is to find
out what the actual character(s) is(are). Easiest thing to do there is
to open a file w/ a binary editor and look.

c) once a) and b) are both known to be true and the output required
known, if it's something other than one of the special characters
fprintf knows about, I _think_(+) you'll have to write it w/ fwrite()
after the last fprintf() of regular text files.

(+) Caveat -- I don't recall if there's a C escape sequence in formatted
write to write an arbitrary byte in formatted write or not, or if there
is, if Matlab has it incorporated. My quick perusal doesn't indicate to
me there is but I may be overlooking it.

--

Subject: carriage return at end of file using fprintf???

From: ImageAnalyst

Date: 1 Jun, 2011 20:56:12

Message: 6 of 7

I agree with dpb - it shouldn't be necessary. But if it is, control-Z
was often used as an EOF character so you might try something like
fprintf(fid, '%c', 26);

Subject: carriage return at end of file using fprintf???

From: dpb

Date: 2 Jun, 2011 02:03:58

Message: 7 of 7

On 6/1/2011 3:56 PM, ImageAnalyst wrote:
> fprintf(fid, '%c', 26)

Good call for the "workaround", IA.

W/ the display page here that does display a boxy-looking character so
that is likely what OP has.

Shouldn't be needed for anything other than an old 16-bit DOS app, however.

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us