An C Example


A C Example

I am a graduated German computer engineer and software engineer.Among my core programming languages is the programming language C.Please take the program below as a reference.If you want your own C program to be written from me,contact me with :

Tel. : +4915172972526


E-Mail : [email protected]


/* voucher writer */
/* 2023 by Juergen Josef Schmidt */
#include
/* the name of the file the voucher should be written to */
char fname[80];
/* the name of the issuer,at most 4 words separated by blanks */
char vheader[4][80];
/* a char representing the amount,must be one digit */
char c;
/* the name of the overlayed currency,at most 4 words,separated by blanks*/
char currName[4][80];
/* the underlying currency and its amount,at most 3 words separated by blanks*/
char equals[4][80];
/* the dash line,increase array size,if you need longer line */
char delim[80]="--------------------------------------------";
/* write voucher with amount and currency name, based on another (possibly electronic) currency */
void writeVoucher()
{
FILE *fp = fopen(fname,"w");
fprintf(fp,"%s\n",delim);
fprintf(fp,"\n");
fprintf(fp,"%s %s %s %s\n\n",vheader[0],vheader[1],vheader[2],vheader[3]);
/* note amount is always one digit */
fprintf(fp,"%c %s %s %s %s\n\n",c,currName[0],currName[1],currName[2],currName[3]);
fprintf(fp,"%s %s %s %s\n",equals[0],equals[1],equals[2],equals[3]);
fprintf(fp,"\n\n");
fprintf(fp,"%s\n",delim);
fclose(fp); }
/* fetch voucher data and write voucher to file */
int main()
{
printf("Filename of target text: ");
fscanf(stdin,"%s",fname);
printf("\nIssuer name : ");
fscanf(stdin,"%s %s %s %s",vheader[0],vheader[1],vheader[2],vheader[3]);
printf("\nAmount: ");
/* special constraint to amount : must be 1 or 5 */
do{
c = getc(stdin);
}while((c!='1') && (c != '5'));
printf("\nFull currency name : ");
fscanf(stdin,"%s %s %s %s",currName[0],currName[1],currName[2],currName[3]);
printf("Equivalent in other currency : ");
fscanf(stdin,"%s %s %s %s",equals[0],equals[1],equals[2],equals[3]);
writeVoucher();
}