User Profile

Collapse

Profile Sidebar

Collapse
ConfusedAlot
ConfusedAlot
Last Activity: May 20 '07, 01:47 PM
Joined: Mar 11 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • ConfusedAlot
    replied to Classes and structures
    in C
    One last thing,

    I have a sort member function that passes data to other functions;

    Code:
    void OpAmps::Sort(OpAmps* Op, unsigned long length)
    
      switch(UserInput) {
        case '1':
          // sort according to name (in alphabetical order)
    		qsort(Op,length,sizeof(OpAmps),&OpAmps::SortName);
          break;
          
        case '2':
          // sort according to slew rate (in
    ...
    See more | Go to post

    Leave a comment:


  • ConfusedAlot
    replied to Classes and structures
    in C
    Im not sure...

    I have declared all the functions within the class now, so they are all accessible to one another, in the menu system i have for example;

    Code:
          case '1':
    		  Enter(OpAmpObject[database_length], database_length);
            break;
    I know that OpAmpObject is not defined in the class, and therefore cannot be accessed even though it is declared in main as type OpAmps, the point that...
    See more | Go to post

    Leave a comment:


  • ConfusedAlot
    replied to Classes and structures
    in C
    Thank you! so i changed that, and now im having problems with the fact that the object im creating is being converted from a struct to object oriented, except, im not sure how to do this and all the errors are related to the fact that in the menu code the left of .Enter, .Save etc are not class/struct/union! also i have an error that says that OpAmpObject is undeclared, except ive created it in main from the OpAmpDb class;

    Code:
    int main()
    ...
    See more | Go to post

    Leave a comment:


  • ConfusedAlot
    replied to Classes and structures
    in C
    I have 2 header files and one cpp file.

    object.h contains;

    Code:
    struct OpAmps {
      char Name[20];  // the name of the op-amp (e.g. "741")
      unsigned int PinCount;  // the number of pins in the package
      double SlewRate;
    };
      
    class OpAmpDb
    {
    public:
    	OpAmpDb();
    	void Enter(OpAmps&, unsigned long&);
    	void Save(const OpAmps*, unsigned
    ...
    See more | Go to post

    Leave a comment:


  • ConfusedAlot
    started a topic Classes and structures
    in C

    Classes and structures

    I have a structured piece of code that i am converting into object orientated, the structured code contains a stuct;


    Code:
    struct OpAmps {
      char Name[20];  // the name of the op-amp (e.g. "741")
      unsigned int PinCount;  // the number of pins in the package
      double SlewRate;  // the slew rate in volts per microsecond
    };

    This struct needs to be included in the OO code...
    See more | Go to post
    Last edited by AdrianH; May 5 '07, 03:52 PM. Reason: Please use [code][/code] tags for readibility

  • ConfusedAlot
    replied to Saving to file
    in C
    thanks, so last thing, in the Load function, i always get a length of zero, it is supposed to read the first line of the text file and then read the corresponding entries, the first line in the file is the number 3, so it should read three, but doesnt, ideas??

    Code:
    void Load(OpAmps* OpAmp, unsigned long& length)
    {  
      fstream input_file;  // file stream for input
    
       //open the file
    
      input_file.open(DATABASE_FILENAME,
    ...
    See more | Go to post
    Last edited by Ganon11; Mar 16 '07, 12:12 PM. Reason: code tags added

    Leave a comment:


  • ConfusedAlot
    replied to Saving to file
    in C
    I have changed a part of the save function to this:

    unsigned int i;
    for (i=0;i<length;i ++);
    {
    //output_file.wri te((const char*)&OpAmp[i], sizeof(OpAmps)) ;
    output_file << endl;
    output_file << OpAmp[i].Name << endl;
    output_file << OpAmp[i].PinCount << endl;
    output_file << OpAmp[i].SlewRate << endl;

    but...
    See more | Go to post

    Leave a comment:


  • ConfusedAlot
    replied to Saving to file
    in C
    So in the console that works fine, but in the database.txt file the program creates the information is not stored conrrectly. The file only contains the length and then alot of garbage, cant seem to pinpoint where the code is wrong
    ideas??
    See more | Go to post

    Leave a comment:


  • ConfusedAlot
    started a topic Saving to file
    in C

    Saving to file

    This is my code for a database, whenever i save the database to the file 'database.txt' and display the results i get this;

    name - (correct, is what i put in)
    pin - 3435973836
    slew rate - -9.25596e+061

    these values are the same for every entry i add, i cant seem fo figure out why.

    Plus, the text file i save to is supposed to have the format of

    length

    Name...
    See more | Go to post
    Last edited by horace1; Mar 15 '07, 05:25 PM. Reason: add code tags

  • ConfusedAlot
    started a topic Illegal breaks
    in C

    Illegal breaks

    I have this function within my program, it allows the user to enter things into a database, the only problem is, when i use the program i cannot get out of the enter operational amplifier stage, when i add a break into the code i get an error of illegal break, how do i fix this??
    Code:
    void Enter(OpAmps& OpAmp, unsigned long& length)
    // if the database is full, inform the user
    {
    	char line[20];
    	unsigned
    ...
    See more | Go to post
    Last edited by sicarie; Mar 15 '07, 01:57 PM. Reason: Added [code] and [/code] tags

  • so i changed the for (i=0;i=length;i ++) to (i=0;i<=length; i++) but the file created does not show the data entered by the user which are to be saved... help!!
    See more | Go to post

    Leave a comment:


  • Having problems with the save function, the debugger gets down to the cout line for opening file and then just stops, i think i need to declare a pointer to the structure but then i get errors in the lines that write the name etc to the file
    Code:
    void Save(OpAmps OpAmp[], unsigned long length)
    {  
      fstream output_file;  // file stream for output
    
      // open the file
      //<enter code here>
    ...
    See more | Go to post
    Last edited by horace1; Mar 14 '07, 04:45 PM. Reason: added cide tags

    Leave a comment:


  • ConfusedAlot
    started a topic Passing structure to function, help!!
    in C

    Passing structure to function, help!!

    I have a database called OpAmps with 3 members, name, pincount and slewrate

    I have a menu system where the save function arguments are stated as

    Save(OpAmp, database_length )

    OpAmps OpAmp[DATABASE_MAX]

    is defined above and database max is ten, database length is 0 to begin with

    When creating the function prototype i have written

    void Save(OpAmps, unsigned long)//opamp...
    See more | Go to post

  • Ive already changed that in the code im working on, took me a while to realise it, my main problem is the error code i referred to in an early post, ive tried a few combinations of arguments to be passed but not getting anywhere
    See more | Go to post

    Leave a comment:


  • This is the function prototype for Save

    Code:
    int Save(OpAmps, unsigned long);
    This is the portion in main where save is called

    Code:
          case '2':
            Save(OpAmp, database_length);
            break;
    This is the function so far

    Code:
    // Save the database to the file specified by DATABASE_FILENAME. If the file exists it
    // simply overwritten without asking the user
    ...
    See more | Go to post
    Last edited by Ganon11; Mar 12 '07, 01:12 PM. Reason: code tags added

    Leave a comment:


  • Thankyou, when i debug the code my main error is when passing the struct into the Save, Load and Display functions, i get the error, cannot convert parameter 1 from OpAmps[10] to 'OpAmps' how would i correct this?
    See more | Go to post

    Leave a comment:


  • Structures and functions when writing/reading to file

    I am having difficulty defining the function prototypes and corresponding parameters when the function is called from main. Any help is greatly appreciated.

    Code:
    //The database
    
    struct OpAmps {
      char Name[20]; 
      unsigned int PinCount; 
      double SlewRate;
    
    //The function prototypes
    
    void Enter(OpAmps );
    int Save(OpAmps );
    void Load(OpAmps );
    void
    ...
    See more | Go to post
    Last edited by sicarie; Mar 11 '07, 11:16 PM. Reason: Added [ code] and [ /code] tags (without the spaces)
No activity results to display
Show More
Working...