Write a .txt file in C -
i'm trying write in file in format, when open file in notepad, it's not want. if decrease size of window (for notepad), becomes became want, if maximize little bit, format changes.
my code generate file is:
#include <stdio.h> #include <stdlib.h> void main(){ file *fp,*fp2; int i=0; int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12; fp=fopen("treino01.bin","r"); fp2=fopen("treino02.txt","w"); fprintf(fp2,"estc\tndep\trenda\ttipor\tvbem\tnparc\tvparc\ttel\tidade\tresms\tentrada\tclasse\n",num1,num2,num3,num4,num5, num6,num7,num8,num9,num10,num11,num12); while( (fscanf(fp, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", &num1, &num2, &num3, &num4, &num5, &num6, &num7, &num8, &num9, &num10, &num11, &num12))!= eof ){ printf("%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\n",num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12); fprintf(fp2,"%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\n",num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12); } fclose(fp); fclose(fp2); }
the first file file like:
12 fields , each field represented numbers, it's table.
the second file read first file , insert comma after each number (1,).
what need insert comma after each number.
potential problem of line terminators on windows. can try this:
fp2 = fopen("treino02.txt", "wt");
please note "t" in mode parameter.
Comments
Post a Comment