声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1687|回复: 3

[编程技巧] 【求助】读入txt时如何不让空格丢失

[复制链接]
发表于 2008-12-15 10:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
程序段为:
fid1=fopen('input.txt','rt');
s=fscanf(fid1,'%s');
fclose(fid1);

加入input.txt中内容为:
Skip to content.Skip to bbc.co.uk navigation.Skip to bbc.co.uk search.The BBC is not responsible for the content of external internet sites.
结果为:
s=Skiptocontent.Skiptobbc.co.uknavigation.Skiptobbc.co.uksearch.TheBBCisnotresponsibleforthecontentofexternalinternetsites.

读入的txt文件为一段纯英文字符串,读入工作空间后空格丢失,用了多种读入函数(dlmread,fread等)均无法解决,请教高人。
回复
分享到:

使用道具 举报

发表于 2008-12-15 12:39 | 显示全部楼层

  1. >> fid1=fopen('input0.txt','rt');s=fgetl(fid1);fclose(fid1);
  2. >> s

  3. s =

  4. Skip to content.Skip to bbc.co.uk navigation.Skip to bbc.co.uk search.The BBC is not responsible for the content of external internet sites.

复制代码
发表于 2008-12-15 13:09 | 显示全部楼层
fid1=fopen('input.txt','rt');
s=fscanf(fid1,'%c');  %  换个读取格式就行了
fclose(fid1);

评分

1

查看全部评分

 楼主| 发表于 2008-12-15 14:20 | 显示全部楼层
非常感谢!!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 23:17 , Processed in 0.056737 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表