第一種方法:
1.網上流行的乙個方法: 列印出每行的文字資訊。
#include #include int main(void)
if (line)
free(line);
exit(exit_success);
}
2.我自己稍作修改,取得指定行數的文字資訊。
#include #include int get_file_line(char *pinputname, char *poutputbuf, int cnt)
if (line)
return -3;
}int main(void)
; int j;
for(j=1;j<8;++j)
printf("\n");
}
執行以下,結果如圖:
在此處做乙個小小的拓展,就是在每行的文字資訊中提取我們想要的資訊:
#define dindexname "www"
#define name_len_max 7
void getname(void)
; char dest_name[20]=;
char pfilename[256]="test.txt";
get_file_line(pfilename,line,1);
printf("line === %s \n",line);
if((p=strstr(line,dindexname))&&(p=strchr(line,':')))
for(i=0;i
執行結果,如下所示:
第二種方法:
#include #include #include #include #include typedef unsigned char u8;
int get_file_line(char *pinputname, int line)
ttempflag=0;}}
}else if( ptempbuffer[n]>=0x20 )
n++;
}if( (n>m)&&(ttempflag) )
ttempcmdflag=0;
}free(ptempbuffer);
}close(ttempfile);
return ttempcmdflag;
} }
return 2;
}void main(void)
有點長,但是也算一種辦法啦。 Linux 命令 echo 顯示一行文字
echo option string n不輸出行尾的換行符。e允許對轉義字元進行解釋。e禁止對轉義字元進行解釋,這是預設的選項。help 顯示幫助資訊。version 顯示版本資訊。轉義字元 含義 反斜槓 a警報符 bel b退格符 c禁止尾隨的換行符 e換碼符 f換頁符 n換行符 r回車符 t水平...
一行文字居中多行文字左對齊
lang en charset utf 8 titletitle head 當文字為一行是,則p的寬度小於div的寬度,p標籤居中顯示在盒子內,文字也就居中了 當大於一行時,p的寬度和div的寬度是一致的 文字就居左對齊了 rk box display inline block使p的寬度根據文字的寬...
一行文字中的最長單詞
問題 已知 string sentence we were her pride of 10 she named us benjamin,phoenix,the pordigal and perspicacious pacific suzanne.要求 計算sentence中有多少個單次,並指出其中最...