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(); }
C语言输出到文件的方法
最新推荐文章于 2024-10-01 10:00:00 发布