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

如题所述

第1个回答  2015-01-16
#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;} 查看更多答案>>

求采纳本回答被提问者采纳