net-server/client/func/readtext.c
macbook-pro dd35c14a17 use ggg
2023-12-21 11:56:09 +08:00

53 lines
835 B
C

void readtext(){
FILE *f;
int i=0;
int num_text=0;
char a;
int i_text=0;
int acount_text=0;
//acount the num of char and row
f=fopen(name,"r+");
a=fgetc(f);
for(;a!=EOF;){
if(a=='\n'){
i++;
}
num_text++;
a=fgetc(f);
}
fclose(f);
row_text=i;
//write the text to []
text=(char *)malloc(sizeof(char)*(num_text+1));
ana_text=(int *)malloc(sizeof(int)*(row_text+1));
f=fopen(name,"r+");
a=fgetc(f);
for(i=0;i<num_text;i++){
text[i]=a;
if(a=='\n'&&i_text<=row_text){
*(ana_text+i_text)=acount_text;
acount_text=0;
i_text++;
}
else{
acount_text++;
}
a=fgetc(f);
}
text[i]='\0';
*(ana_text+i_text)='\0';
fclose(f);
ana_row=(int *)malloc(sizeof(int)*(row_text+1));
row_display=0;
for(i=0;i<row_text;i++){
*(ana_row+i)=*(ana_text+i)/COLS+1;
row_display+=*(ana_row+i);
}
}