Thread: cpp issues

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    90

    cpp issues

    Hello Guru's.
    I'm comming from VB background so have nightmare to switch to C/C++ in rewriting of simple programs, actually, to start ith cpp.

    So, situation is:
    header il.h

    Code:
    int ReadIL(bool RW, long ILRecord, IL);
    struct ILRec
    {
        char myRowStr[30];
        int myRowInt;
        float myRowf;
        char myNextStr[300];
    }IL;
    then:
    file il.cpp

    Code:
    #include "il.h"
    #include <stdio.h>
    #include <string.h>
    
    int ReadIL(RW, ILRecord, IL)
        {
         int ILLength=sizeof(struct ILRec);
    
            FILE *f;
            f=fopen("junk.dat","wb+");
            if (ILRecord<1) ILRecord=1;
            if (!f) return 1;
              {
                fseek(f,(ILLength*(ILRecord-1)),SEEK_SET);
                if (RW)
                {
              //  strcpy(IL.myRowStr,"my string to file");
                fwrite(&IL, ILLength, 1, f);
                }
                else
                {
                fread(&IL, ILLength, 1, f);
                }
              }
             fclose(f);
             return 0;
        }
    In my main cpp program I have also included il.h
    and from there I call function like this:

    Code:
    long ILRecord=1;
    ReadIL(false, ILRecord, IL);
    And I get several errors during compiling
    C:\Users\John\Desktop\aaa\il.h|1|error: 'IL' has not been declared|
    C:\Users\John\Desktop\aaa\aaaMain.cpp||In member function 'void aaaFrame::OnbtnOpenClick(wxCommandEvent&)':|
    C:\Users\John\Desktop\aaa\aaaMain.cpp|344|error: cannot convert 'ILRec' to 'int' for argument '3' to 'int ReadIL(bool, long int, int)'|
    ||=== Build finished: 2 errors, 0 warnings ===|

    Purpose of wanted program is to chose a record in Main program (ILRecord) and to get required data in structure IL from function ReadIL from other file in same project.
    What do I do bad and how to get this to work?
    Please for recommendation at newbie level.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by nime
    I'm comming from VB background so have nightmare to switch to C/C++ in rewriting of simple programs, actually, to start ith cpp.
    Are you switching to C or C++? They are two different programming languages.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2010
    Location
    Halesowen, England
    Posts
    30
    First error says:
    il.h|1|error: 'IL' has not been declared|
    In il.h, you need to define IL at a variable type, so add the red bit below:
    Code:
    typedef struct ILRec
    {
        char myRowStr[30];
        int myRowInt;
        float myRowf;
        char myNextStr[300];
    }IL;

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    90
    laserlight, I know that I work with file at C way and this is because of better simmilarity with my VB programs.

    Jamdog, donned, but now again this...


    C:\Users\John\Desktop\aaa\il.h|1|error: 'IL' has not been declared|
    C:\Users\John\Desktop\aaa\aaaMain.cpp||In member function 'void aaaFrame::OnbtnOpenClick(wxCommandEvent&)':|
    C:\Users\John\Desktop\aaa\aaaMain.cpp|345|error: expected primary-expression before ')' token|
    ||=== Build finished: 2 errors, 0 warnings ===

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    90
    Ups, I added il.h to my main.h and only one error lefts:

    C:\Users\John\Desktop\aaa\il.h|1|error: 'IL' has not been declared|
    ||=== Build finished: 1 errors, 0 warnings ===|

    Obviously is needed to make IL "public", but how to do this?

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I suggest you start fresh, forget about VB, pick up a C book or tutorial and immerse yourself in a new world. Trying to adapt to writing in another language like you do in one you already know is most likely a futile exercise to begin with. The same goes with actual languages, you can't expect to apply what you know in English in order to learn German.
    Last edited by claudiu; 09-27-2010 at 05:08 AM.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    90
    So, If I want to learn german language I should first forget english?
    Mein Gott!

    Btw, we have here simple issue with propper organizing files in c++ project...

  8. #8
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    The error itself tells you what is wrong... "IL undeclared". Why would it say this? It apears you declared IL so is anything ABOVE the declaration of IL that uses IL? Dunno if that will make all your problems go away, but I'm assuming the error you are getting is because of the function that is declared above IL and is told that it requires a IL as a parameter, but the compiler doesn't yet know what a IL is.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  9. #9
    Registered User
    Join Date
    Mar 2010
    Posts
    90
    Lesshardtofind,
    I noticed that and moved declaration of function below struct, but error persist.

    Code:
    typedef struct ILRec
    {
        char myRowStr[30];
        int myRowInt;
        float myRowf;
        char myNextStr[300];
    }IL;
    int ReadIL(bool RW, long ILRecord, IL);
    Of course, I can't yet figure why error commes and what REALY, but when I read a file at same way in main module everything is ok, without error.
    Maybe somebody with more expirience on this things can know...

  10. #10
    Registered User
    Join Date
    Nov 2008
    Posts
    127
    Code:
    int ReadIL(bool RW, long ILRecord, IL);
    Probably has something to do with that line.

    Code:
    int ReadIL(RW, ILRecord, IL)
    Is declared wrong too. You needs types and var names when declaring functions.
    Last edited by homer_3; 09-27-2010 at 07:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help converting c dll to cpp
    By *DEAD* in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 10:22 PM
  2. includein cpp file in a cpp file
    By sawer in forum C++ Programming
    Replies: 7
    Last Post: 06-15-2006, 12:34 PM
  3. Replies: 2
    Last Post: 04-09-2006, 07:20 PM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. i do i get started on cpp file
    By jlmac2001 in forum C++ Programming
    Replies: 5
    Last Post: 02-24-2003, 08:55 PM