Home Forums C Programming Read 1st col vals of i/pfile;create o/p fl for each diff val Re: Re: Read 1st col vals of i/pfile;create o/p fl for each diff val

#3606
GWILouisaxwzkla
Participant

Heres some code that does what you want ( maybe you can splice this into your program ):



/****************************************************************
* File Name : c:programstempCG.cpp
* Date : August,10,2009
* Comments : new project
* Compiler/Assembler : Visual C++ 6.0
* Modifications :
*
*
*
*
*
* Program Shell Generated At: 3:17:50 p.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/



#include < stdio.h >
//#include < conio.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >

//using namespace std;

//main function ******************************

int main ( )
{

//CHANGE FILE NAMES TO WHAT YOU WANT HERE !!!!!!!!!!!!!!!!!!!!!

FILE * inputFile = fopen ( "c:\programs\data.txt", "r+" );

FILE * outputFile;


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

char ch;
char newline = 10;
int commaCount;


char fileName [ 50 ] ;
strcpy ( fileName , "c:\programs\" );


fileName [ 12 ] = fgetc ( inputFile );
fileName [ 13 ] = fgetc ( inputFile );
fileName [ 14 ] = '.';
fileName [ 15 ] = 't';
fileName [ 16 ] = 'x';
fileName [ 17 ] = 't';
fileName [ 18 ] = 0;
fgetc ( inputFile );
while ( ! feof ( inputFile ) )
{



ch = fgetc ( inputFile );
outputFile = fopen ( fileName , "a" );
commaCount = 0;
while ( ch != newline && commaCount < 4)
{
if ( ch == ',' )
commaCount ++;
else
fputc ( ch , outputFile );
ch = fgetc ( inputFile );
}
fputc ( ' ' , outputFile );
//flush rest of line
while ( ch != newline )
ch = fgetc ( inputFile );
fclose ( outputFile );



fileName [ 12 ] = fgetc ( inputFile );
fileName [ 13 ] = fgetc ( inputFile );
fileName [ 14 ] = '.';
fileName [ 15 ] = 't';
fileName [ 16 ] = 'x';
fileName [ 17 ] = 't';
fileName [ 18 ] = 0;
fgetc ( inputFile );
}


return 0 ;
}