C语言输出到文件的方法

C语言输出到文件的方法: 1、输出到txt文件中。 #include main() { FILE *fp; int i; int year = 2007; int month = 12; int day = 4; fp = fopen("log.txt","wb+" ); for( i = 0; i< 65; i++ ){ fprintf( fp,"[CHAR] baseColor(%c)/n", i ); printf( "%d/n", i ); } fprintf(fp,"YEAR:%2d MONTH:%2d DAY:%2d/n", year,month,day); fclose( fp ); } 2、输出到csv文件中。 #include #define RM_LOGS_PATH "./Logs" main() { int bkColor = 1, echoColor = 2; int B_targetTrailColor = 2; int B_gradation = 2; int i = 1, j = 1, k = 1; static char *echoStr[] = { "Yellow", "Green", "Orange", "Multi" }; static char *bkStr[] = { "Black", "DkBlue", "Blue", "White" }; static char *trailStr[] = { "Green", "Red", "Blue", "White", "Black" }; static char *trailGradStr[] = { "Single", "Multi" }; FILE *fp; char fileName[128]; /*sprintf( fileName, "%s/Trail/Echo_%s/Back_%s_Trail_%s_%s.csv", RM_LOGS_PATH, echoStr[echoColor], bkStr[bkColor], trailStr[B_targetTrailColor], trailGradStr[B_gradation] ); */ fp = fopen( fileName, "w" ); if( fp == NULL ){ return( NULL ); } fprintf( fp, "/n// Color Pallete for Trail/n" ); fprintf( fp, "// BackGround: (%d)%-8s ", bkColor, bkStr[bkColor] ); fprintf( fp, "Trail: (%d)%-8s Grad: (%d)%-8s Echo: (%d)%-8s/n", B_targetTrailColor, trailStr[B_targetTrailColor], B_gradation, trailGradStr[B_gradation], echoColor, echoStr[echoColor] ); fprintf( fp, "// shift_min [%2d] base_val[%2d] shift_max[%2d]/n", i, j, k ); fprintf( fp, "%2d,%4d,%4d,%4d/n", i, j, k, i ); if( fp ){ fprintf( fp, "/n" ); fclose( fp ); } getch(); }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值