File csvconverter.c of Package sassas

/***************************************************************************
 *   Copyright (C) 2007 by Pham Van Manh   *
 *   manhpv@localhost.localdomain   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <include/stringlib.h>
#include <string.h>


int main(int argc, char *argv[])
{
	char buf[MAX_LENGTH+1];
	FILE * f_out;
	FILE *f_in;
	FILE *f_header;
    char answer='y';
                                                 
	
	printf("           CSV Converter             ");
	printf("\n---------------------------------\n");
	//****************************************
	//Output file
	printf("Enter output file (*.csv):");
	fgets(buf,MAX_LENGTH+1,stdin);
	buf[strlen(buf)-1]='\0';
	f_out = fopen(buf,"a");	
	if(!f_out)
	{
	printf("Error while open output file \n");
	return 0;
	}
	//*************************************	
	//*************************************
	//Header file[MAX_LENGTH+1]
	printf("Enter header file:");
	fgets(buf,MAX_LENGTH+1,stdin);
	buf[strlen(buf)-1]='\0';
	f_header = fopen(buf,"r");
	if(!f_header)
	{
	printf("Header file is not exist\n");
	return 0;
	}

 	 while( fgets(buf,MAX_LENGTH+1,f_header) )
	{		
		buf[strlen(buf)-1]='\0';
		fputs(buf,f_out);
		fputs("`",f_out);
	}
	fputs("\n",f_out);
	//*************************************	
	
while(answer=='y')
{
    //*****************************}********
	//Input file
	printf("Enter input file:");
	fgets(buf,MAX_LENGTH+1,stdin);
	buf[strlen(buf)-1]='\0';
	f_in = fopen(buf,"r");
	if(!f_in)
	{
	printf("Input file is not exist\n");
	return 0;
	}
	//***************************************	
	printf("Converting...\n");
	rewind(f_header);
	char * info;
    while( fgets(buf,MAX_LENGTH+1,f_header) )
	{				
		rewind(f_in);
		buf[strlen(buf)-1]='\0';	
	    info=searchInfo(f_in,buf);
		//Replace 10 and 13 char in string info 
		replace(info,10,' ');
		replace(info,13,' ');
		fputs(info,f_out); 	
		fputs("`",f_out); 	
	}
	fputs("\n",f_out); 	
	printf("Finish!\n");
	printf("Do you want to continue(y/n)");
    answer=getchar();
	if(answer=='n')
	 printf("To view result.Open csv file with separate char`\n");
    else
	fgets(buf,MAX_LENGTH+1,stdin);
 }
	fclose(f_in);
	fclose(f_out);
	fclose(f_header);

	return 1;
}
openSUSE Build Service is sponsored by