# 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. ## 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. 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. 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. Uh yeah... Sure. Here's the C code... header is up next...

5. Yeah...

6. 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.
*/
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
* Note: this falls through to the default
* to print an "unknow option" message
*/
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

7. 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; };

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. 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...

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. 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));

free(freightor_a);`