H
hpy_awad
I am writing stings ((*cust).name),((*cust).address)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM
*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];
};
main()
{
clrscr();
printf ("-----------------------------------------------------------------------------");
printf ( "\nThis is run of program") ;
printf ( "E:\programs\\cpp\\iti01\\ch09\\ex09_5p1.cpp\n");
printf ( "
-------------------------------------------\n");
void customer_input(struct customer_record *cust);
struct customer_record customer;
char another_customer;
//open file for output
FILE *fp_rental;
if ((fp_rental=fopen("input","w"))==NULL)
{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
exit (0);
}
// do while more customers
do {
//input customer date
customer_input(&customer);
//write customer date to file
fprintf(fp_rental,"%4d %2d %c %s %s",customer);
printf("\n Another customer");
scanf("\n");
scanf("%c",&another_customer);
} while ((another_customer)=='y');
//write end of record
fprintf(fp_rental,"%4d %2 d %c %s %s",9999,99,' ',' ',' ');
//clsoe files
fclose(fp_rental);
return 0;
}
void customer_input(struct customer_record *cust)
{
printf("\n Enter customer number : ");
scanf ("%4d",&(*cust).customer_no);
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust).no_of_weeks);
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust).tv_type);
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust).name);
gets((*cust).name);
printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust).address);
gets((*cust).address);
}
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM
*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];
};
main()
{
clrscr();
printf ("-----------------------------------------------------------------------------");
printf ( "\nThis is run of program") ;
printf ( "E:\programs\\cpp\\iti01\\ch09\\ex09_5p1.cpp\n");
printf ( "
-------------------------------------------\n");
void customer_input(struct customer_record *cust);
struct customer_record customer;
char another_customer;
//open file for output
FILE *fp_rental;
if ((fp_rental=fopen("input","w"))==NULL)
{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
exit (0);
}
// do while more customers
do {
//input customer date
customer_input(&customer);
//write customer date to file
fprintf(fp_rental,"%4d %2d %c %s %s",customer);
printf("\n Another customer");
scanf("\n");
scanf("%c",&another_customer);
} while ((another_customer)=='y');
//write end of record
fprintf(fp_rental,"%4d %2 d %c %s %s",9999,99,' ',' ',' ');
//clsoe files
fclose(fp_rental);
return 0;
}
void customer_input(struct customer_record *cust)
{
printf("\n Enter customer number : ");
scanf ("%4d",&(*cust).customer_no);
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust).no_of_weeks);
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust).tv_type);
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust).name);
gets((*cust).name);
printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust).address);
gets((*cust).address);
}