📄 addcr.c
字号:
#include<stdlib.h>#include<stdio.h>#define SYM_LF '\n'#define SYM_CR '\r'#define NOCR 0#define LINUX_T 1#define WIN_T 2/*chain node data struct * struct chain_node{char num;char str[20];struct chain_node *pre;};*/main(){FILE *fp=fopen("./itsme","r");fseek(fp,0,SEEK_END);char nlstr=0;//the length of file,long type varient file length less than 4Glong length=ftell(fp);fseek(fp,0,SEEK_SET);char *swap1=malloc(length);fread(swap1,1,length,fp);long i,j;long CR_cnt;char t_flag;CR_cnt=0;t_flag=NOCR;//count the number of CR symbol in the text stream//judge the type of text at the same timefor(i=0;i<=length;i++){if(swap1[i]==SYM_LF) {CR_cnt++; if(t_flag!=LINUX_T) {t_flag=LINUX_T; if((i>0)&&(swap1[i-1]==SYM_CR)) t_flag=WIN_T; } }}if(t_flag==NOCR) puts("There is only 1 line in the text!");if(t_flag==LINUX_T) puts("This is a Linux type text(LF for newline)!");if(t_flag==WIN_T) puts("This is a Windows type text(CR+LF for newline)!");//now we learn the length of new streamchar *swap2=malloc(length+CR_cnt);j=0;for(i=0;i<=length;i++){if(swap1[i]==SYM_LF) {swap2[j]=SYM_CR;j++;}swap2[j]=swap1[i];j++;}swap2[j]=EOF;FILE *fp_1=fopen("./new","w");fwrite(swap2,1,j-1,fp_1);/*while(!feof(fp)){fread(&nlstr,1,1,fp);if(nlstr=='\n') }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -