ConvertTab2Div.c
純文字檔開頭的\t轉換成div的縮排程式,並輸出成output.txt。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 #include <stdio.h> #include <stdlib.h> #include <string.h> /* 程式說明 純文字檔開頭的\t轉換成div的縮排程式,並輸出成output.txt 使用方法 cc 此檔名.c ./此檔名.此副檔名 要轉換文字檔 注意! 只有開頭的\t會轉成div。 換行字元是unix的換行字元,如果是windows的字元請用dos2unix這個程式轉換一下 */ int main ( int argc , char * argv [ ] ) { if ( argc != 2 ) { printf ( "argc Error!\n" ) ; } FILE * pfi ; FILE * pfo ; char buf [ 513 ] ; pfi = fopen ( argv [ 1 ] , "r" ) ; pfo = fopen ( "output.txt" , "w" ) ; int lastLineTab = 0 , nowLineTab = 0 , newLine = 1 , haveDiv = 0 ; fprintf ( pfo , "<div>\n" ) ; while ( fgets ( buf , 2 , pfi ) != NULL ) { ...