#includeintmain(intargc,char*argv[]){intch;FILE*fpinPtr,*fpou" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

UNIX2DOS工具

系統 1962 0

今天寫了一個UNIX2DOS工具,用于把UNIX系統的文本轉換成DOS(Windows)下支持的文本。

兩大操作系統文本主要的不同在于換行時UNIX里只有 '\n'字符,而在DOS(Windows)下變成了'\r\n'。


廢話不多說,此工具用C語言寫成,源代碼如下:

?

// unix2dos
//
#include? < stdio.h >
#include?
< stdlib.h >

int ?main( int ?argc, char ? * argv[])
{
????
int ?ch;
????FILE?
* fpinPtr, * fpoutPtr;

????
if ?(argc != 3 )
????{
????????printf(
" UNIX2DOS?program.\n\n " );
????????printf(
" Usage:?command?source_file?target_file\n " );
????????printf(
" Usage?example:?\ " unix2dos?src.txt?obj.txt\ " \n " );
????????exit(EXIT_FAILURE);
????}

????
if ?((fpinPtr = fopen(argv[ 1 ], " rb " )) == NULL)
????{
????????printf(
" Input?file?\ " % s\ " ?could?not?be?opened\n " ,argv[ 1 ]);
????????exit(EXIT_FAILURE);
????}

????
if ?((fpoutPtr = fopen(argv[ 2 ], " wb " )) == NULL)
????{
????????printf(
" Outout?file?\ " % s\ " ?could?not?be?opened\n " ,argv[ 2 ]);
????????exit(EXIT_FAILURE);
????}

????
while ( ! feof(fpinPtr))
????{
????????ch
= fgetc(fpinPtr);
????????
if (ch >- 1 ? && ?ch? != ? ' \n ' )
????????{
????????????fputc(ch,fpoutPtr);
????????}
????????
else ? if (ch >- 1 )
????????{
????????????fputc(
' \r ' ,fpoutPtr);
????????????fputc(ch,fpoutPtr);
????????}

????}

????fclose(fpinPtr);
????fclose(fpoutPtr);

????
return ? 0 ;
}

?

當然,還有一個附加產品:DOS2UNIX,源代碼如下:


// dos2unix
//
#include? < stdio.h >
#include?
< stdlib.h >

int ?main( int ?argc, char ? * argv[])
{
????
int ?ch;
????FILE?
* fpinPtr, * fpoutPtr;

????
if ?(argc != 3 )
????{
????????printf(
" DOS2UNIX?program.\n\n " );
????????printf(
" Usage:?command?source_file?target_file\n " );
????????printf(
" Usage?example:?\ " DOS2UNIX?src.txt?obj.txt\ " \n " );
????????exit(EXIT_FAILURE);
????}

????
if ?((fpinPtr = fopen(argv[ 1 ], " rb " )) == NULL)
????{
????????printf(
" Input?file?\ " % s\ " ?could?not?be?opened\n " ,argv[ 1 ]);
????????exit(EXIT_FAILURE);
????}

????
if ?((fpoutPtr = fopen(argv[ 2 ], " wb " )) == NULL)
????{
????????printf(
" Outout?file?\ " % s\ " ?could?not?be?opened\n " ,argv[ 2 ]);
????????exit(EXIT_FAILURE);
????}

????
while ( ! feof(fpinPtr))
????{
????????ch
= fgetc(fpinPtr);
????????
if (ch >- 1 ? && ?ch? != ? ' \r ' )
????????{
????????????fputc(ch,fpoutPtr);
????????}
????}

????fclose(fpinPtr);
????fclose(fpoutPtr);

????
return ? 0 ;
}

?


參考代碼源:HP UNIX CP命令?,歡迎各位高手批評指正。?


Wednesday, May 06, 2009

?

?

UNIX2DOS工具


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 涿鹿县| 句容市| 陕西省| 郯城县| 太仆寺旗| 崇信县| 公安县| 大余县| 巴彦淖尔市| 赣州市| 蓬莱市| 岫岩| 冷水江市| 浦江县| 拜城县| 沁阳市| 昭苏县| 潼南县| 左贡县| 大余县| 安溪县| 木里| 辽宁省| 普陀区| 唐河县| 陆河县| 镇远县| 曲麻莱县| 南京市| 辛集市| 蒙阴县| 张家川| 民乐县| 郁南县| 郓城县| 收藏| 日土县| 全椒县| 浮梁县| 东光县| 澄迈县|