永发信息网

C语言怎样从文本中读取 数据避免换行符的干扰而且对字符串操作后原文本数据还是逐行输出

答案:2  悬赏:0  手机版
解决时间 2021-03-17 16:35
  • 提问者网友:蓝琪梦莎
  • 2021-03-16 18:35
C语言怎样从文本中读取 数据避免换行符的干扰而且对字符串操作后原文本数据还是逐行输出
最佳答案
  • 五星知识达人网友:妄饮晩冬酒
  • 2021-03-16 19:29
#includestdio.h#includestdlib.h#includestring.h#includeiostream.h// 替换字符串中特点字符串为指定字符串int replace(char *sSrc, char *sMatchStr, char *sReplaceStr){ int StringLen; char caNewString[100]; char *FindPos = strstr(sSrc, sMatchStr); if( (!FindPos) || (!sMatchStr) ) return ⑴; while( FindPos ) { memset(caNewString, 0, sizeof(caNewString)); StringLen = FindPos - sSrc; strncpy(caNewString, sSrc, StringLen); strcat(caNewString, sReplaceStr); strcat(caNewString, FindPos + strlen(sMatchStr)); strcpy(sSrc, caNewString); FindPos = strstr(sSrc, sMatchStr); }return 0;}int main(){int i=0;char s[100],a[]=Cylinder height: ,b[]= radius: ,c[]= ;FILE *fp;fp=fopen(E:\\maxscript脚本\\1234.txt,r+);if(fp==NULL){printf(cannot open file code.txt);exit(1);} while((fgets(s,100,fp))!=NULL){ replace(s,(,a); replace(s,,,b);replace(s,),c); fputs(s,fp); printf(%s,s) ;}fseek(fp,0,0);fclose(fp);return 0;} 查看更多答案>>

求采纳
全部回答
  • 1楼网友:十年萤火照君眠
  • 2021-03-16 21:00
#includestdio.h#includestdlib.h#includestring.h#includeiostream.h// 替换字符串中特点字符串为指定字符串int replace(char *ssrc, char *smatchstr, char *sreplacestr){ int stringlen; char canewstring[100]; char *findpos = strstr(ssrc, smatchstr); if( (!findpos) || (!smatchstr) ) return ⑴; while( findpos ) { memset(canewstring, 0, sizeof(canewstring)); stringlen = findpos - ssrc; strncpy(canewstring, ssrc, stringlen); strcat(canewstring, sreplacestr); strcat(canewstring, findpos + strlen(smatchstr)); strcpy(ssrc, canewstring); findpos = strstr(ssrc, smatchstr); }return 0;}int main(){int i=0;char s[100],a[]=cylinder height: ,b[]= radius: ,c[]= ;file *fp;fp=fopen(e:\\maxscript脚本\\1234.txt,r+);if(fp==null){printf(cannot open file code.txt);exit(1);} while((fgets(s,100,fp))!=null){ replace(s,(,a); replace(s,,,b);replace(s,),c); fputs(s,fp); printf(%s,s) ;}fseek(fp,0,0);fclose(fp);return 0;}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯