Large Data management in using File

This is a discussion on Large Data management in using File within the C Programming forums, part of the General Programming Boards category; hi members. i am programming student information system in C Language as my semester project... for this i need Student ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Pakistan
    Posts
    4

    Question Large Data management in using File

    hi members.

    i am programming student information system in C Language as my semester project... for this i need


    Student Registeration Number string type
    Name string type
    Father Name string type
    Date of birth string type
    Programme string type
    and marks in six subjects. array of six integers

    every thig is working fine like. add new record, delete record, searching of record, updation of record, report of individual and full record.. all the data is stored in arrays of structured temperory. now i want to write this all data to file when i want to exit from the programe. and next time when i run program it read data from file first then manipulate with data and before exit the program the new data is write to file??

    here i have 2 different data types. string and integers. plz suggest me what should i do now?
    quick repsponse please

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    You should... start coding right away?

    This forum is for asking questions, not for asking answers.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  3. #3
    Registered User Rennor's Avatar
    Join Date
    Aug 2006
    Location
    Finland
    Posts
    45
    fread()
    fwrite()


  4. #4
    Registered User
    Join Date
    Sep 2006
    Location
    Pakistan
    Posts
    4
    these functions i know. can i write different type of data to file and also read from file?

  5. #5
    Registered User
    Join Date
    Sep 2006
    Location
    Pakistan
    Posts
    4
    here is my program. now i want to add file handling in it.

    Code:
    // Programmed By Mohsan Hassan
    // 219-FAS/BSSE/F05
    
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include<string.h>
    #include<dos.h>
    #include<process.h>
    #include<iostream.h>
    #define SIZE	3
    
    struct student{
    	char no[10];
    	char name[30];
    	char f_name[30];
    	char dob[20];
    	char prg[30];
    	int mks[6];
    };
    student std_db[SIZE];
    
    // User Defined Functions
    void menu();
    void create();
    void add();
    void search();
    void update();
    void deletee();
    void report();
    void report_ind();
    void report_full();
    
    int i=0,cdb=0;
    
    void main()
    {
    	clrscr();
    	menu();
    	getch();
    }
    
    		// To Display Main Menu
    void menu()
    {
    clrscr();
    int x=5,y=1;
    int ch;
    gotoxy(25,y);
    cout <<"Student Information System";
    gotoxy(x,y+=3);
    cout << "1 - Create Data Base";
    gotoxy(x,y+=3);
    cout << "2 - Add New Record";
    gotoxy(x,y+=3);
    cout << "3 - Search Record";
    gotoxy(x,y+=3);
    cout << "4 - Update Record";
    gotoxy(x,y+=3);
    cout << "5 - Delete Record";
    gotoxy(x,y+=3);
    cout << "6 - Report";
    gotoxy(x,y+=3);
    cout << "7 - Exit";
    cout <<"\n\nChoose Your Choice:";
    cin >> ch;
    switch(ch)
    {
    	case 1:
    	{
    	create();
    	break;
    	}
    	case 2:
    	{
    	add();
    	break;
    	}
    	case 3:
    	{
    	search();
    	break;
    	}
    	case 4:
    	{
    	update();
    	break;
    	}
    	case 5:
    	{
    	deletee();
    	break;
    	}
    	case 6:
    	{
    	report();
    	break;
    	}
    	case 7:
    	{
    //	char *aut="Programmed By Mohsan Hassan  219-FAS/BSSE/F05";
    //		for(int t=0;t<(strlen(aut));t++)
    //		{
    //			cout << aut[t];
    //			delay(100);
    //		}
    		getch();
    	exit(0);
    	break;
    	}
    	default:
    	{
    	menu();
    	break;
    	}
    }
    
    }
    	// To Create New Data Base
    void create()
    {
    if(cdb==1)
    {
    clrscr();
    cout << "\n\nData Base is already created";
    getch();
    menu();
    }
    int n=1;
    char em='y';
    clrscr();
    	while(em=='y' || em=='\r')
    		{
    		if(i>=SIZE)	// to check array max length
    			{
    			clrscr();
    			cout << "\n\nMemory Full";
    			getch();
    			menu();
    			}
    		clrscr();
    		cout << "\nEnter Student Number:";
    		cin >> std_db[i].no;
    		cout << "Enter Student Name:";
    		gets(std_db[i].name);
    		cout << "Enter Father Name:";
    		gets(std_db[i].f_name);
    		cout << "Enter Date of Birth(ddmmyy):";
    		gets(std_db[i].dob);
    		cout << "Enter Programme:";
    		gets(std_db[i].prg);
    		for(n=0;n<6;n++)
    		{
    			cout << "\nEnter Marks in Subject " << n+1<<":";
    			cin >> std_db[i].mks[n];
    		}
    		i++;
    		cout <<"\nAdd More(y/n):";
    		em=getche();
    		}
    cdb=1;
    getch();
    menu();
    }
    	// To Add new record
    void add()
    {
    		if(i>=SIZE)	// to check array max length
    			{
    			clrscr();
    			cout << "\n\nMemory Full";
    			getch();
    			menu();
    			}
    
    	clrscr();
    	cout << "\nEnter Student Number:";
    	cin >> std_db[i].no;
    	cout << "Enter Student Name:";
    	gets(std_db[i].name);
    	cout << "Enter Father Name:";
    	gets(std_db[i].f_name);
    	cout << "Enter Date of Birth(ddmmyy):";
    	gets(std_db[i].dob);
    	cout << "Enter Programme:";
    	gets(std_db[i].prg);
    	for(int n=0;n<6;n++)
    	{
    		cout << "\nEnter Marks in Subject " << n+1<<": ";
    		cin >> std_db[i].mks[n];
    	}
    	i++;
    cout << "\n\nRecord Added Successfully";
    getch();
    menu();
    }
    
    	// To search any record
    void search()
    {
    clrscr();
    char no[10];
    int tmp=0;
    cout << "Enter Student Number:";
    cin >> no;
    clrscr();
    for(int j=0;j<=i;j++)
    {
    	tmp=strcmp(no,std_db[j].no);
    	if(tmp==0)
    	break;
    }
    	if(tmp==0)
    	{
    	cout << "\nStudent Number:\t\t"<<std_db[j].no<<endl<<endl;
    	cout << "Student Name:\t\t"<<std_db[j].name<<endl<<endl;
    	cout << "Father Number:\t\t"<<std_db[j].f_name<<endl<<endl;
    	cout << "Date of Birth:\t\t"<<std_db[j].dob<<endl<<endl;
    	cout << "Program:\t\t"<<std_db[j].prg<<endl<<endl;
    	for(int k=0;k<6;k++)
    		cout << "Marks in Subject:"<<k+1<<"\t\t"<<std_db[j].mks[k]<<endl<<endl;
    	getch();
    	}
    	else
    	{
    		cout << "\n\nRecord Not Found";
    		getch();
    	}
    menu();
    }
    	// To update any record
    void update()
    {
    char no[10];
    int tmp=0;
    clrscr();
    cout << "Enter Student Number:";
    cin >> no;
    clrscr();
    for(int j=0;j<=i;j++)
    {
    	tmp=strcmp(no,std_db[j].no);
    	if(tmp==0)
    	break;
    }
    	if(tmp==0)
    		{
    			cout << "\nPlease Update record\n\n";
    			cout << "Enter Student Name:";
    			gets(std_db[j].name);
    			cout << "Enter Father Name:";
    			gets(std_db[j].f_name);
    			cout << "Enter Date of Birth:";
    			gets(std_db[j].dob);
    			cout << "Enter Programme:";
    			gets(std_db[j].prg);
    			for(int n=0;n<6;n++)
    			{
    				cout << "\nEnter Marks in Subject "<<n+1<<": ";
    				cin >> std_db[j].mks[n];
    			}
    			cout << "\n\nRecord Updated Successfully";
    			getch();
    		}
    		else
    		{
    		cout << "\n\nRecord Not Found";
    		getch();
    		}
    
    menu();
    }
    	// To delete any record
    void deletee()
    {
    char no[10];
    int tmp=0;
    clrscr();
    cout << "Enter Student Number:";
    cin >> no;
    clrscr();
    for(int j=0;j<=i;j++)
    {
    	tmp=strcmp(no,std_db[j].no);
    	if(tmp==0)
    	break;
    }
    	if(tmp==0)
    	{
    	for(int z=j;z<i;z++)
    	{
    	std_db[z]=std_db[z+1];	// to copy next element of arrayed structure to previous one
    	}
    	i-=1;
    	cout << "\n\nRecord Deleted";
    	getch();
    	}
    	else
    	{
    	cout << "\n\nRecord Not Found";
    	getch();
    	}
    
    
    menu();
    }
    	// to display report of any record
    void report()
    {
    int ch;
    clrscr();
    cout << "\t\t1 - Individual Report\n\n\n";
    cout << "\t\t2 - Full Report\n\n";
    cout << "Enter Your Choice:";
    cin >> ch;
    switch(ch)
    	{
    		case 1:
    		{
    		report_ind();
    		break;
    		}
    		case 2:
    		{
    		report_full();
    		break;
    		}
    	}
    menu();
    }
    	// to display individual record
    void report_ind()
    {
    clrscr();
    for(int j=0;j<i;j++)
    {
    	clrscr();
    	cout << "\nStudent Number:\t\t"<<std_db[j].no<<endl<<endl;
    	cout << "Student Name:\t\t"<<std_db[j].name<<endl<<endl;
    	cout << "Father Number:\t\t"<<std_db[j].f_name<<endl<<endl;
    	cout << "Date of Birth:\t\t"<<std_db[j].dob<<endl<<endl;
    	cout << "Program:\t\t"<<std_db[j].prg<<endl<<endl;
    	for(int k=0;k<6;k++)
    		cout << "Marks in Subject:"<<k+1<<"\t\t"<<std_db[j].mks[k]<<endl<<endl;
    	cout << "\nPress Any Key To View Next Record";
    	getch();
    }
    }
    // to display report of full record
    void report_full()
    {
    int y=4;
    int x=40;
    clrscr();
    for(int j=0;j<80;j++)
    cout << "-";
    cout << "No  Name   Father   DOB       Program  Sub 1  Sub 2  Sub 3  Sub 4  Sub 5  Sub 6\n";
    for(j=0;j<80;j++)
    cout << "-";
    for(j=0;j<i;j++)
    	{
    	x=40;
    	gotoxy(1,y);
    	cout << std_db[j].no;
    	gotoxy(5,y);
    	cout << std_db[j].name;
    	gotoxy(12,y);
    	cout << std_db[j].f_name;
    	gotoxy(21,y);
    	cout << std_db[j].dob;
    	gotoxy(31,y);
    	cout << std_db[j].prg;
    	for(int k=0;k<6;k++)
    	{
    	gotoxy(x,y);
    	cout <<std_db[j].mks[k];
    	x+=7;
    	}
    	y++;
    		// To control Screen Limit
    		if(y==10)
    		{
    			cout << "\nPress Any Key to Continue";
    			getch();
    			y=4;
    			clrscr();
    			for(int j=0;j<80;j++)
    			cout << "-";
    			cout << "No  Name   Father   DOB       Program  Sub 1  Sub 2  Sub 3  Sub 4  Sub 5  Sub 6\n";
    			for(j=0;j<80;j++)
    			cout << "-";
    		}
    	}
    getch();
    }
    Last edited by Ken Fitlike; 09-14-2006 at 06:16 AM. Reason: code tags added

  6. #6
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    This may be the ugliest piece of code I've seen all summer. Firstly, 2 things need
    to be done:

    1. Code Tags need to be added.
    2. Move thread to the C++ board.

    The amount of bad practices in this code one finds on just a skim over it is
    amazing.

    EDIT: Excellent work Ken - very fast!!!

    Now that we're in the right place, I can tell you that what you want to do is quite
    doable - look at this.

    You have an awful amount of issues with this code that you should also address:

    1. Mixing C code and C++ code is generally a bad thing - pick one language and
    stick to it.
    2. void main is bad, and gets is absolutely intolerable!!! See my sig for some
    informative links on them.
    3. Using C header files instead of their C++ versions (cstdio, for example).
    4. Including unnecessary headers - dos.h and process.h
    5. Using an out of date header - iostream.h
    Last edited by Richie T; 09-14-2006 at 06:31 AM.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  7. #7
    Registered User
    Join Date
    Sep 2006
    Location
    Pakistan
    Posts
    4
    hi.
    actually i wrote this program in proper formation. but when i post it here all the lines gone to first column.
    and i m new to C++ and have knowledge of C so my code is mixture of C and C++. thanks for advices.......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 10:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21