#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
Author: Racav
This example shows how to create "EMPLOYEES.RPV" report using C++ language.
Take into account that file "PERSON.DAT" is in "program files". If you don't have an ENGLISH
version of Windows, you should change that by the right directory.
Programmer uses "*separate_words" routine to separate the line using comma.
*/
char *separate_words(char *word1,char separator,int num_word);
void main(void)
{
FILE *in, *out;
char buff[256];
char sep_buff[256];
out = fopen("C:\program files\rpv\samples\employees.rpv","wt");
fputs("report_title=Employees report Example with C++n",out);
fputs("orientation=2n",out);
fputs("open_viewn",out);
fputs("spacing=250n",out);
fputs("$c0=400n",out);
fputs("$c1=1000n",out);
fputs("$c2=3400n",out);
fputs("$c3=6800n",out);
fputs("$c4=8400n",out);
fputs("$c5=11000n",out);
fputs("$c6=13000n",out);
fputs("$c7=13200n",out);
fputs("[header]n",out);
fputs("{f=arial;s=8}n",out);
fputs("{pic=c:\program files\rpv\samples\rpvlogo.bmp;400,400,1400,900}n",out);
fputs("{\n;$c7} Page {12800;pag}n",out);
fputs("{s=16;\n;1800;c=2;b=y} Sample Application Report {spacing=350;\n}n",out);
fputs("{c=1;1800} Employees Report {\n}n",out);
fputs("{c=0;b=n;\n;\n;\n}n",out);
fputs("{line=400,14000;\n}n",out);
fputs("{s=8;b=y;$c0} Id {$c1} Name {$c2} Address {$c3} Phone {$c4} E-Mail",out);
fputs("{$c5} Birth Date {a=r;$c6} Monsalary {a=l;$c7} Schedule {b=n;spacing=375;\n}n",out);
fputs("{line=400,14000;\n}n",out);
fputs("[data]n",out);
in = fopen("c:\program files\rpv\samples\person.dat", "rt");
while (!feof(in))
{
fgets(buff,256,in);
strcpy(sep_buff,separate_words(buff,',',1));
fputs("{$c0}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',2));
fputs("{$c1}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',3));
fputs("{$c2}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',4));
fputs("{$c3}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',6));
fputs("{$c4}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',7));
fputs("{$c5}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',8));
/* If the word number 8 (mon salary) < than 1400 then turns red */
if (atoi(sep_buff) < 1400)
fputs("{a=r;$c6;c=12}",out);
else
fputs("{a=r;$c6}",out);
fprintf(out,"%s",sep_buff);
strcpy(sep_buff,separate_words(buff,',',10));
fputs("{c=0;a=l;$c7}",out);
fprintf(out,"%s",sep_buff);
fputs("{\n}n",out);
}
fclose(in);
fclose(out);
}
char *separate_words(char *word1,char separator,int num_word)
{
char buff[256];
int buff1;
int cc=0;
int j=0;
for (int i=0;i<strlen(word1);i++)
{
if (word1[i] != separator)
{
buff1 = word1[i];
buff[j] = buff1;
j++;
}
else
{
cc++;
if (cc == num_word)
break;
else
{
buff[0]=' ';
j=0;
}
}
}
buff[j] = ' ';
return buff;
} |