Help! File Handling!!!

This is a discussion on Help! File Handling!!! within the C++ Programming forums, part of the General Programming Boards category; Hey guyz, dis is sevenaces this is my first post at c boards... but i have a problem here. i ...

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

    Red face Help! File Handling!!!

    Hey guyz, dis is sevenaces
    this is my first post at c boards...
    but i have a problem here.
    i need to make a prgrm to sort a binary file with a class w.r.t a specific variable maybe a variable 'x' arranged alphabetically...
    it hs to be mostly c++...using most c commands is not allowed...
    and the most important thing...
    it has to be done using pointers to handle the file...
    pls help me out...

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    1)Search for solutions on your own
    2)Post your attempts
    3)Grammer is your friend

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    4
    well..after wasting quite sum couple of hrs i messed uo and hv started to write it again...
    here's wat i hv gt till nw...

    Code:
    #include<iostream.h>
    #include<fstream.h>
    
    class bin
    {
    private:
    	int a;
    public:
    	bin(int a)
    	{
    		cout<<"\n   Pointer successfuly created...";
    	}
    	bin()
    	{
    		cout<<"\n   Enter values for the object : ";
    		cin>>a;
    		wtf();
    	}
    	void wtf();
    	void rfm();
    } s;
    
    void main()
    {
    	bin *p;
    	int n, i;
    	cout<<"\n   Enter no of objects to be created : ";
    	cin>>n;
    	i=n-1;
    	while(i)
    	{
    		i--;
    		p=new bin;	
    		delete(p);
    	}
    	s.rfm();
    
    }
    
    void bin::rfm()
    {
    	int i=0;
    	ifstream f;
    	f.open("bin");
    	f.seekg(0, ios::beg);
    	f.read((char*)&s, sizeof(s));
    	cout<<"\n   The following data is present : ";
    	while(f)
    	{
    		cout<<"\n   Record no."<<++i;
    		cout<<"\n   A = "<<s.a;
    		f.read((char*)&s, sizeof(s));
    	}
    	f.close();
    }
    
    void bin::wtf()
    {
    	ofstream f;
    	f.open("bin", ios::app);
    	f.write((char*)&s, sizeof(s));
    	f.close();
    }

    i yet hv to rewrite the func. sorting...

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    #include<iostream.h>
    #include<fstream.h>
    That should be:
    Code:
    #include<iostream>
    #include<fstream>
    void main()
    should be:
    Code:
    int main()
    You member function names need to be more descriptive.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >		p=new bin;	
    //Here you would want to call wtf
    		p.wtf();
    >		delete(p);
    >	}
    >	s.rfm();
    //Here you could create a new instance of the class, then call rfm
    	s temp;
    	temp.rfm();

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    4
    forget about what code i hav given....
    please just someone post the function for sorting....
    Last edited by sevenaces; 09-29-2006 at 03:09 AM.

  7. #7
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    std::sort
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  8. #8
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Keep typing like that and you will probably not recieve much more help here. Some of us may not be sophisticated, but we all enjoy that people show the curtisy to not type like morons... lets examine your posts.

    'guyz' takes same number of keystrokes, but you have to reach in a more awkward way than to hit an s.

    'dis' is one of the few that is a time saver in the end, but this is not german and we are not going towards the germanic roots of english, please just use 'th' when it should be there.

    'prgrm' not only is it wrong but it looks silly. Program is only 2 more letters.

    'w.r.t' I have no idea what that is.

    'hs' come on, 'a' is right there when you are hitting 's'.

    'pls' is the only one that is commonly used on the net that I have seen so far, by people who type in a mannor that is readable, but if you are asking for help, why not take the time to spell it out.

    'sum' is the result of adding numbers, 'some' is the word you were looking for.

    'hrs' common shortening, no big deal.

    'uo' common typo... again no biggy.

    'hv' this one is what lead me to believe the hs of above wasn't just a typo, 2 extra letters, dont be lazy.

    'wat' perhaps you are a native spanish speaker and forgot about the 'h' I know a couple people who natively speak spanish and make this mistake.

    'gt' maybe you just loath vowels... but if that were the case, 'wat' would be 'wht' hmmm...

    '4get' you save 2 keystrokes and have to reach farther...

    Anyway. I gotta go, please respect the members of the board more.

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    903
    You write like a retard. Besides, all your variables have completely meaningless names which is a big no-no.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    4
    which variable do you think make no sense???

  11. #11
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> You write like a retard.
    What was that in aid of? /!\

    >> Besides, all your variables have completely meaningless names which is a big no-no.
    I agree, but I am a self-admitted pedantic with respect to naming functions/variables and code formatting, so I'm rather biased.

    Wraithan w,r,t - with respect to. I was gonna use that in the above text, it's kinda eng-speak which is why I know it. I generally assume nobody knows the acronyms I do, so i tend not to use them.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >You write like a retard.
    I agree. This is a message board, not a chat bot. And if you think someone's going to do your homework for you here, think again.

  13. #13
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Ok, the wrt one is my fault, I assumed it was some sort of trashtyping speak. I have never seen that acronym.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating File Handling Functions
    By td4nos in forum C Programming
    Replies: 6
    Last Post: 06-26-2009, 11:43 AM
  2. basic file handling problem
    By georgen1 in forum C Programming
    Replies: 4
    Last Post: 03-05-2009, 05:21 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

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