problem in fprintf

hi,
In the following code ,at first I opened file for reading in order to replace '|' with ','.
Then I opened another file for writing the the above data. Each time the number of ',' equal 23 , the writing of data in file will be in new line.
But, the resulting file just one line .
%%%%%%%%%%%%%%%%%%%%%
the code:
f=fopen('u2.txt','r');%%%%%%open the original data file
b=fscanf(f,'%s');
for i=1:length(b)
if b(i)=='|'
b(i)=',';
end
end
k=0;
f1=fopen('u4.txt','w+');
for j=1:length(b)
fprintf(f1,'%s',b(j));
if b(j)==','
k=k+1;
end
if k==23
k=0;
fprintf(f1,'%s','\n');
end
end
%%%%%%%%%%%%%%%%%
thanks

回答(1 个)

Walter Roberson
Walter Roberson 2011-9-13

0 个投票

Either use just about any other editor than the one you are using to view the file, or else use 'wt+' instead of 'w+' when you open the output file.
Note: you should really only use 'w+' or 'wt+' if you are going to be using fseek() to move around in the output file while it is still open. If all you need to do is write the file, then please use 'w' for binary files and 'wt' for text files.

类别

帮助中心File Exchange 中查找有关 Low-Level File I/O 的更多信息

标签

提问:

2011-9-13

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by