I have a problem with this code. Why this shows random symbols when i give view data ! ?
#include<iostream>
#include<conio.h>
#include<windows.h>
#include "gotoxy.h"
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<fstream.h>
using namespace std;
//function declarations
void out(char *);
void matrix(int,int);
class student
{
public:
//class variable declaration in public part
int roll,fee,ht,wt;
char adminno[10],name[30],yn,imark[30],save,blood[10],n[30],age[3],sch[300],clas[10],s[7],address[50],fn[30],mn[30],
joinclass[10],secondlang[10],primlang[10],ph[15],mobil[11],fo[20],mo[20],brosis[30],date[9],time[9],dob[9],fpos;
//constructor
student()
{
roll=ht=wt=0;
strcpy(primlang,"English");
}
// Getting student information from user
void adform()
{
top:
fflush(stdin);
system("cls");
out ("\n Admission Number : ");
cin >> adminno;
fflush(stdin);
out (" Student's name : ");
gets(n);
fflush(stdin);
out(" Class Joining : ");
gets(joinclass);
out(" Primary Language : English\n");
fflush(stdin);
out("Secondary Language : ");
gets(secondlang);
out (" Father's name : ");
gets(fn);
out (" Mother's name : ");
gets(mn);
out (" Date of Birth : ");
gets(dob);
out (" Address : ");
gets(address);
out (" Father's Occupation : ");
gets(fo);
out (" Mother's Occupation : ");
gets(mo);
out (" Age : ");
gets(age);
out (" Sex : ");
gets(s);
out (" Phone Number : ");
gets(ph);
out (" Mobile Number : ");
gets(mobil);
fflush(stdin);
out (" Height : ");
cin >> ht;
fflush(stdin);
out (" Weight : ");
cin >> wt;
fflush(stdin);
out (" Blood Group : ");
gets(blood);
fflush(stdin);
out (" Identification Marks : ");
gets(imark);
cout <<"\n";
}
//end of user get info function
//saves the data to file
void filesave()
{
FILE *fp;
fp=fopen(adminno,"w");
fprintf(fp,"%s",adminno);
fprintf(fp," ");
fputs(n,fp);
fprintf(fp," ");
fputs(joinclass,fp);
fprintf(fp," ");
fputs(primlang,fp);
fprintf(fp," ");
fputs(secondlang,fp);
fprintf(fp," ");
fputs(fn,fp);
fprintf(fp," ");
fputs(mn,fp);
fprintf(fp," ");
fputs(dob,fp);
fprintf(fp," ");
fputs(address,fp);
fprintf(fp," ");
fputs(fo,fp);
fprintf(fp," ");
fputs(mo,fp);
fprintf(fp," ");
fputs(age,fp);
fprintf(fp," ");
fputs(s,fp);
fprintf(fp," ");
fputs(ph,fp);
fprintf(fp," ");
fputs(mobil,fp);
fprintf(fp," ");
fprintf(fp, "%d",ht);
fprintf(fp," ");
fprintf(fp, "%d",wt);
fprintf(fp," ");
fputs(blood,fp);
fprintf(fp," ");
fputs(imark,fp);
fprintf(fp," ");
fclose(fp);
}
}; //end of class
//intro screen
void welcome()
{
system("cls");
system("color 0E");
gotoxy(35,13);
out ("Student Management");
Sleep(500);
gotoxy(33,14);
out(" (C) MAD Groups 2011");
Sleep(3000);
}
//credits
void thank()
{
system("cls");
system("color 0a");
gotoxy(35,4);
out ("Manoj Kumar K R");
gotoxy(35,6);
out ("Arun Shankar T S");
gotoxy(35,8);
out ("Dinesh Kumar K");
gotoxy(35,10);
out ("GopiNath P");
gotoxy(35,12);
out ("Deepak R");
gotoxy(35,14);
out ("Praveen Karthikeyan A S");
gotoxy(8,20);
system("color 02");
out ("Thank you for using a Geniune Product of MAD Groups,Infinite Ltd.");
Sleep(5000);
}
//global constant variables
const long int clas = 32;
const long int students = 50;
//fancy cout function for printing
void out(char s[100])
{
for(int i=0;i<=strlen(s);i++)
{
Sleep(50);
cout << s[i];
}
}
//function to scan and print data
void scandata(char *);
void scandata(char a[10])
{
student s1;
FILE *fp;
fp=fopen(a,"r");
//scans data
while(!EOF)
{
fflush(stdin);
fscanf(fp,"%s",s1.adminno);
fscanf(fp,"%s",s1.name);
fscanf(fp,"%s",s1.joinclass);
fscanf(fp,"%s",s1.primlang);
fscanf(fp,"%s",s1.secondlang);
fscanf(fp,"%s",s1.fn);
fscanf(fp,"%s",s1.mn);
fscanf(fp,"%s",s1.dob);
fscanf(fp,"%s",s1.address);
fscanf(fp,"%s",s1.fo);
fscanf(fp,"%s",s1.mo);
fscanf(fp,"%s",s1.age);
fscanf(fp,"%s",s1.s);
fscanf(fp,"%s",s1.ph);
fscanf(fp,"%s",s1.mobil);
fscanf(fp,"%d",s1.ht);
fscanf(fp,"%d",s1.wt);
fscanf(fp,"%s",s1.blood);
fscanf(fp,"%s",s1.imark);
fflush(stdin);
fclose(fp);
}
//prints data
system("cls");
printf("\nAdmission Number : %s",s1.adminno);
printf("\nname : %s ",s1.name);
printf("\nClass Joining : %s ",s1.joinclass);
printf("\nPrimary Language : %s ",s1.primlang);
printf("\nSecondary Language : %s ",s1.secondlang);
printf("\nFather's name : %s",s1.fn);
printf("\nMother's name : %s",s1.mn);
printf("\nDate of Birth : %s",s1.dob);
printf("\nAddress : %s",s1.address);
printf("\nFather's Occupation %s",s1.fo);
printf("\nMother's Occupation %s",s1.mo);
printf("\nAge : %s",s1.age);
printf("\nSex : %s",s1.s);
printf("\nPhone Number : %s",s1.ph);
printf("\nMobile Number : %s",s1.mobil);
printf("\nHeight : %d",s1.ht);
printf("\nWeight : %d",s1.wt);
printf("\nBlood Group : %s",s1.blood);
printf("\nIdentification Marks : %s",s1.imark);
getch();
}//end of file reading,printing function
//main function
int main()
{
int i=1;
unsigned long int n;
char yn,save,admin[10];
student s2;
welcome();
//main menu
start:
system("cls");
system("color 0B");
out("\n\n\n\n Enter an option : \n");
out("\n 1. Enter Data ");
out("\n 2. View Data ");
out("\n 3. Edit Data ");
out("\n 4. Exit \n");
out(" ");
cin >> n;
//menu options - switch case
switch(n)
{
case 1:
s2.adform();
out (" Press 's' to save and continue\n");
out ("Press 'c' to clear details\n");
out ("Press 'v' to save and quit\n");
out ("Press 'q' to quit without saving\n");
enter:
cin >> save;
switch(save)
{
case 's':s2.filesave();s2.adform();
case 'c':s2.adform();
case 'v':s2.filesave();break;
case 'q':break;
default: out("Invalid option...\n");goto enter;
}
break;
case 2:out ("Enter the admission number : ");
cin >> admin;
scandata(admin);
break;
case 3:out ("Enter the admission number : ");
cin >> admin;
break;
case 4:goto exit;
default : out ("\n\a\a Try Again");for(int k=1;k<=3;k++){Sleep(1000);cout << ".";}Sleep(1000);;goto start;
}
goto start;
//end of prog with credits
exit:
thank();
return(0);
}