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

Writting to a .tx file

Asked by Suzie on 22 Apr 2013

I am creating a high score table for a game. I created a .txt file that has a name in the first column and a two digit score in the second column.

I am trying to make it so a user can input their name and their score onto the file.

So far I have... fid = fopen('HighScoreTable.txt', 'w');

data = textscan(fid, '%s %d');

close = fclose(fid);

names = data{1}

scores = data{2}

But it is giving me this error message ..

Error using textscan Unable to read any data from the file, textscan may not have read access.

Error in Table (line 5) data = textscan(fid, '%s %d');

0 Comments

Suzie

Products

No products are associated with this question.

1 Answer

Answer by per isakson on 22 Apr 2013

Writing or reading?

Try

    fid = fopen('HighScoreTable.txt', 'r' );

with an "r" for reading. textscan does only reading.

0 Comments

per isakson

Contact us