lcc32 wedit <-- need help with this

This is a discussion on lcc32 wedit <-- need help with this within the Windows Programming forums, part of the Platform Specific Boards category; True, many compilers vary slightly, I however, followed the tutorials off of this website and get such errors as: Warning ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    11

    Unhappy lcc32 wedit <-- need help with this

    True, many compilers vary slightly, I however, followed the tutorials off of this website and get such errors as:

    Warning c:\lcc\projects\database\alpha\000001\alpha\db_a00 0001a.c:
    c:\lcc\projects\database\alpha\000001\alpha\mud1.h : 16 missing prototype for money // What's this mean? I have it declared in the structure with the rest and it's the only one that does this...
    Error c:\lcc\projects\database\alpha\000001\alpha\db_a00 0001a.c: 64 undeclared identifier `freighter' // It's declared in mud1.h though...
    Warning c:\lcc\projects\database\alpha\000001\alpha\db_a00 0001a.c: 64 Statement has no effect // It says this, yet I followed the structures tutorial on this website to the letter, this line is where I typed "freighter gamma;" which is supposed to create an instance of the structure (a variable that contains modifiable variables...) right?

    I also get errors such as:

    Error c:\lcc\projects\database\alpha\000001\alpha\db_a00 0001a.c: 70 operands of = have illegal types `int' and `pointer to int'

    Here's the code anyways:

    freighter gamma;
    freighter *freighter_a;

    planetoids planets;
    planetoids *starport;

    if (freighter freighter_a && planetoids starport) {
    freighter_a.name = "Gamma";
    freighter_a.maxfuel = 2000;
    freighter_a.fuel = freighter_a.maxfuel;
    freighter_a.maxcargo = 150;
    freighter_a.cargo = 0;
    freighter_a.cargo_type = 0;
    freighter_a.speed = 100;
    freighter_a.dest = 0;
    freighter_a.x = 0;
    freighter_a.y = 0;
    freighter_a.money = 5000;

    starport.p1x = 0;
    starport.p1y = 0;
    starport.p1s = 200;

    starport.p2x = 150;
    starport.p2y = -50;
    starport.p2s = 50;

    starport.p3x = 100;
    starport.p3y = 100;
    starport.p3s = 150;

    starport.rate1 = 0.5;
    starport.rate2 = 0.8;
    starport.rate3 = 1.25; }

    freighter_a = &gamma;
    starport = &planets;

    It's a little messy... All numeric variables are declared "int", freighter_a.money is "double long" and the three rates at the bottom are "float".

    Can anyone help?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    I forgot to add, That LCC32 is the compiler I'm using. It's a Windows GUI compiler/editor. It's fairly good, actually. But the code examples used on this site's tutorials don't get along with the compiler, that's why I'm asking for help with the errors above, but there's a lot more erros than I listed above.

  3. #3
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Why don't you attach the entire code with all the files or e-mail them all to me so I can try it because I cannot tell with the line numbers.

    - Sean

    sean345@yahoo.com

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    Uh yeah... Sure. Here's the C code... header is up next...
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    Yeah...
    Attached Files Attached Files
    • File Type: h mud1.h (469 Bytes, 105 views)

  6. #6
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Ok, I found several of the errors and compiled your program successfully.

    First, you need to typedef the structure so that you can use frieghtor and planetoids to create other structures.

    Code:
    /**************************************************
     * Header file for ..\database\alpha\000001\alpha *
     **************************************************/
    
    #ifdef RAND_MAX
    #undef RAND_MAX
    #define RAND_MAX 0x3
    #endif
    #define dl double long
    
    typedef struct freighter {
    	char *name;
    	int max_fuel;
    	int fuel;
    	int max_cargo,cargo;
    	int cargo_type;
    	int speed;
    	int dest;
    	int x,y;
    	dl money;
    } freighter;
    
    typedef struct planetoids {
    	int p1x,p2x,p3x;
    	int p1y,p2y,p3y;
    	int p1s,p2s,p3s;
    	float rate1,rate2,rate3;
    } planetoids;
    Also RAND_MAX was already defined so what you do is check to see if it is defined. If it is you undefine it and redefine it to your value.

    In the main file you has several errors. First, if you want to set a string a value you need to use strcpy you cannot just say:

    Code:
    Name = "Gamma";  //Wrong
    strcpy(Name, "Gamma");  //Correct
    Second you use freightor.maxfuel when the name of the variable in the structure is friegtor.max_fuel. The compiler cannot tell the difference.

    When you are using a pointer to a structure you need to use "->"
    Code:
    freightor_a.fuel = 5  //WRONG
    freightor_a->fuel = 5  //CORRECT
    Here is the main source file:

    Code:
    /* --- The following code comes from C:\lcc\lib\wizard\textmode.tpl. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    #include "mud1.h"
    void Usage(char *programName)
    {
    	fprintf(stderr,"%s usage:\n",programName," /start");
    	/* Modify here to add your usage message when the program is
    	 * called without arguments */
    }
    
    /* returns the index of the first argument that is not an option; i.e.
       does not start with a dash or a slash
    */
    int HandleOptions(int argc,char *argv[])
    {
    	int i,firstnonoption=0;
    
    	for (i=1; i< argc;i++) {
    		if (argv[i][0] == '/' || argv[i][0] == '-') {
    			switch (argv[i][1]) {
    				/* An argument -? means help is requested */
    				case '?':
    					Usage(argv[0]);
    					break;
    				case 'h':
    				case 'H':
    					if (!stricmp(argv[i]+1,"help")) {
    						Usage(argv[0]);
    						break;
    					}
    					/* If the option -h means anything else
    					 * in your application add code here
    					 * Note: this falls through to the default
    					 * to print an "unknow option" message
    					*/
    				/* add your option switches here */
    				default:
    					fprintf(stderr,"unknown option %s\n",argv[i]);
    					break;
    			}
    		}
    		else {
    			firstnonoption = i;
    			break;
    		}
    	}
    	return firstnonoption;
    }
    
    int main(int argc,char *argv[])
    {
    	if (argc == 1) {
    		/* If no arguments we call the Usage routine and exit */
    		Usage(argv[0]);
    		return 1;
    	}
    	/* handle the program options */
    	HandleOptions(argc,argv);
    	/* The code of your application goes here */
    	if (stricmp(argv[5],"/start")) {
    		freighter gamma;
    		freighter *freighter_a;
    
    		planetoids planets;
    		planetoids *starport;
    
    		freighter_a = &gamma;
    		starport = &planets;
    
    		if (freighter_a && starport) {
    			strcpy(freighter_a->name,  "Gamma");
    			freighter_a->max_fuel = 2000;
    			freighter_a->fuel = freighter_a->max_fuel;
    			freighter_a->max_cargo = 150;
    			freighter_a->cargo = 0;
    			freighter_a->cargo_type = 0;
    			freighter_a->speed = 100;
    			freighter_a->dest = 0;
    			freighter_a->x = 0;
    			freighter_a->y = 0;
    			freighter_a->money = 5000;
    
    			starport->p1x = 0;
    			starport->p1y = 0;
    			starport->p1s = 200;
    
    			starport->p2x = 150;
    			starport->p2y = -50;
    			starport->p2s = 50;
    
    			starport->p3x = 100;
    			starport->p3y = 100;
    			starport->p3s = 150;
    
    			starport->rate1 = 0.5;
    			starport->rate2 = 0.8;
    			starport->rate3 = 1.25;
    		}
    
    		printf("This is a simple database test along with AI that uses something similar to fuzzy logic.");
    		printf("The freighter %s will move between three planets at it's own descretion, hauling cargo back and fourth.", freighter_a->name);
    	}
    	return 0;
    }
    You also were using fprintf way wrong.

    Hope this helps.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    11

    Smile

    Oh, man. Sean, thank you the whole bit.

    There's a few things about C I am still unaware of, so I get frustrated at these little things, IE the typedef, I would have wrote:

    Code:
    typedef struct freighter freighter { int whatever; };
    instead of

    Code:
    typedef struct freighter { int whatever; } freighter;
    I will now go and re-evaluate my waywardness :-)

    Although I must say I thought I had attempted to assign the pointers AFTER the declarations, that's why I had <struct>.<whatever> = ???

    Thanks a million.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    Ok, I got the compiler bugs and warnings worked out. But now I have a problem I REALLY don't understand.

    The program compiles PERFECT, yet when I run it, it gives me an error...

    My comments about the error are in double parenthesis ((like this.))
    lcc runtime: GP fault. ((General protection fault? This compiler sucks?)) Stack trace.

    o main [13] c:\lcc\projects\database\alpha\000001\alpha\db_a00 0001a.c 21 ((This is the line that contains "strcpy(freighter_a->name,"Gamma")" so what's this mean?))
    Fault occured outside of function scope
    • Current instruction: 0x7fc0dbd2 ((So can anyone read hex?))
    Again, the program compiled perfectly fine... But if I'm not mistaken, a stack trace means there's something wrong with one of my variables, specifically the string I'm trying to allocate to "freighter_a->name". I do know, however, that a stack overflow indicates that one of my variables is too large for the variable type assigned.

    Ex. 70000 won't fit into "int number;"

  9. #9
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I think what might be happening is that you are using a pointer to a structure (freightor), but you have not assigned memory for it. The pointer points to a random place in memory and not to a place you want it to.

    If you want frieghtor_a to point to freigtor gamma then you need to add this code:
    Code:
    freightor *freightor_a = &gamma;
    For some reason that above line is not displaying correctly, but it is freightor_a = the location of gamma (use the "and" symbol, shift 7, followed by gamma).

    Also you will need to allocate memory for the char* Name in the structure or change it to:
    Code:
    char Name[256]
    If you want to create a new frieghtor structure in memory then you should do this:
    Code:
    freightor *freightor_a = malloc(sizeof(freightor));
    
    //At the end of your program add this
    free(freightor_a);
    What I think is happening is that you are trying to store the information to where frieghtor_a points, but it has not been assigned. I think your best bet is the first option I gave.

    BTW, LCC-WIN32 is what I use all the time and I think it is one of the best compilers out there.

    - Sean
    Last edited by sean345; 04-25-2002 at 07:09 PM.
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <( ' '<) Simple Programming Question?
    By strigen in forum C Programming
    Replies: 1
    Last Post: 03-05-2009, 02:17 PM
  2. x = x < y < 2; WHY IS THIS ALWAYS TRUE!?
    By sh4k3 in forum C Programming
    Replies: 5
    Last Post: 06-08-2007, 01:00 AM
  3. < overload, references and maps
    By underthesun in forum C++ Programming
    Replies: 7
    Last Post: 04-16-2006, 10:15 PM
  4. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 01:06 PM

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