0

I HAVE AN ASSIGNEMENT IN WHICH I GET STUDENT DATA AND SAVE IT A SEPARATE TEXT FILE , THE MAIN PROBLEM IS THAT IT TAKE ALL THE VALUES BUT DONOT STORE VALUE OF SEM,ADD-NO AND BATCH . KINDLY PLEASE HELP ME .

Coding is :-

#include<iostream.h>

 #include<conio.h>

 #include<fstream.h>

  struct stud
   {
    char *name;
     int roll;
      float gpa;
       char *sem;
      char *batch;
     char *add;
    float cgpa;
   };

  int main()
   {
    clrscr();
     fstream p("\\DATA.TXT",ios::out);
      int check;
	struct stud s;
	   while(check!=4)
	     {
	       clrscr();
	      cout<<"\n\n\t\tWELLCOME TO DATABASE FOR STUDENTS(SEMESTER SYSTEM)";
	      cout<<"\n\n\t\t\t PRESS 1 FOR ENTERING DATABASE";
	      cout<<"\n\n\t\t\t PRESS 2 FOR VIEWING  DATABASE";
	      cout<<"\n\n\t\t\t PRESS 3 FOR DELETING DATABASE";
	      cout<<"\n\n\t\t\t PRESS 4 TO EXIT";
	      cout<<"\n\n\n\n\t\t\tENTER YOUR OPTION : ";
	      cin>>check;
	       if(check==1)
		 {
		   clrscr();
		    cout<<"\n\nENTER STUDENT NAME : ";
		    cout<<"\n\n********************************";
		    cout<<"\n\nENTER ROLL NUMBER  : ";
		    cout<<"\n\n********************************";
		    cout<<"\n\nENTER GPA : ";
		    cout<<"\n\n********************************";
		    cout<<"\n\nENTER YOUR SEMESTER : ";
		    cout<<"\n\n********************************";
		    cout<<"\n\nENTER YOUR BATCH : ";
		    cout<<"\n\n********************************";
		    cout<<"\n\nENTER YOUR AD-NO : ";
		    cout<<"\n\n********************************";
		    cout<<"\n\nENTER YOUR CGPA : ";
		    cout<<"\n\n********************************";
		    gotoxy(21,3);
		    cin>>s.name;
		    gotoxy(21,7);
		    cin>>s.roll;
		    gotoxy(12,11);
		    cin>>s.gpa;
		    gotoxy(22,15);
		    cin>>s.sem;
		    gotoxy(19,19);
		    cin>>s.batch;
		    gotoxy(19,23);
		    cin>>s.add;
		    gotoxy(18,27);
		    cin>>s.cgpa;
		    //EOS for end of entry and EOL for end of line
		    p<<s.name<<"(EOS)"<<s.roll<<"(EOS)"<<s.gpa<<"(EOS)"<<s.sem<<"(EOS)"<<s.batch<<"(EOS)"<<s.add<<"(EOS)"<<s.cgpa<<"(EOF)";
		 }
	   }

    return 0;
   }
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Lerner
0

Please wrap code in code tags! This will preserve indentation you (hopefully) use when actually writing the code. The use of code tags is discussed in the watermarks of the message entry box and in the announcements at the top of the board.

Problems I see in the actual code:
1) It should be iostream and fstream without the .h extensions, and you should use a statement like: using namespace std;

2) conio.h is not a standard file and will not be come with all compilers so you may need to distribute it with any code you want to view on a different compiler.

3) struct stud s;
This is C style code. In C++ it's just:
stud s;

4) name, sem, add, batch are all char *. If you want to use them as strings then you have to declare memory for them to use. This is usually done with the keyword new. Here's an example.

char * name;
name = new char[10];

name can now hold up to nine useable char and a terminal null char. So you can now do something like:

cin >> name;

and actually get a value stored in name. But watch out, if the number of char actually entered is more than 9 you're in for a surprise!

5) if each separate data entry isn't separated by whitespace you're going to get a mess.

6) "EOS" and "EOL" seem reasonably odd ways to separate data in a file. Usually data is delimited by spaces or commas or dashes or semicolons and end of lines are either \r\n or \n depending on which operating system you're using.

You'll find you get better quality answers with better quality questions, so be as specific as possible when asking, include relevant input/output examples if appropriate, include error messages or warnings together with where in the code you are pointed to look for the errors/warnings.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.