20 Feb, 2009, boblinski wrote in the 1st comment:
Votes: 0
Alright, sorry in advance..

I'm trying to add history, this is what I've done:

act_info.c
void do_history              args( ( CHAR_DATA *ch, char *argument ) );


further down in act_info.c
void do_history( CHAR_DATA *ch, char *argument )
{
char buf[MAX_STRING_LENGTH];

if (argument[0] == '?')
{
sprintf(buf,"%s", ch->pcdata->history );
send_to_char(buf,ch);
} else
{
string_append( ch, &ch->pcdata->history );
}
return;
}


nanny.c (just under CON_BREAK_CONNECT)
if(!str_cmp(ch->pcdata->history, "(null)"))
{
free_string(ch->pcdata->history);
ch->pcdata->history = str_dup("");
}


save.c
Under 'fwrite_char'
if(ch->pcdata->history != NULL)
fprintf( fp, "History %s~\n", ch->pcdata->history );


save.c
Under 'fread_char' in case H
KEY ("History", ch->pcdata->history,  fread_string ( fp ) );


interp.c
{"history",         do_history,     POS_DEAD,       0, LOG_NORMAL, 1},


interp.h
DECLARE_DO_FUN( do_history              );



When I try to 'make clean' and make- this is what I get.

Quote
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_history':
act_info.c:2795: error: structure has no member named `history'
act_info.c:2799: error: structure has no member named `history'
make: *** [obj/act_info.o] Error 1
20 Feb, 2009, David Haley wrote in the 2nd comment:
Votes: 0
Looks like you didn't add history to the PC_DATA structure. I'm assuming you're following a snippet or something? Can you give a link to the snippet?
20 Feb, 2009, Vatiken wrote in the 3rd comment:
Votes: 0
act_info.c:2795: error: structure has no member named `history'


You need to add history to your pcdata structure.

ch->pcdata->history

Currently you have no member named 'history' in that structure.
20 Feb, 2009, boblinski wrote in the 4th comment:
Votes: 0
Where do i add it to the pcdata?

the snippet is: History Snip
20 Feb, 2009, David Haley wrote in the 5th comment:
Votes: 0
Huh, looks like the snippet instructions aren't complete. I guess you could try adding "char* history" to the pc_data structure somewhere.
20 Feb, 2009, boblinski wrote in the 6th comment:
Votes: 0
Any help on doing that?
20 Feb, 2009, David Haley wrote in the 7th comment:
Votes: 0
Do you know what structures are, and what member fields are?
20 Feb, 2009, boblinski wrote in the 8th comment:
Votes: 0
No, sorry.
20 Feb, 2009, Tyche wrote in the 9th comment:
Votes: 0
20 Feb, 2009, Skol wrote in the 10th comment:
Votes: 0
boblinski, the structure is stored in merc.h, that would be where to add it.
You'll look for
struct  pc_data


Then in there you'd add:
char *              history;


What you're doing is telling the main structure of pc_data (info only players have) that there's a new field called history where you'll be storing information. The rest of the code you had then points to that part of the structure and says 'hey what's here?'. If there is nothing then it's ok, if there's something and it wants to change it, it free's it and then stores a new string there etc.
20 Feb, 2009, David Haley wrote in the 11th comment:
Votes: 0
I would strongly suggest that you go through the links Tyche provided and get a feel for what all of this stuff does and means. The concept of a struct is absolutely fundamental here, and it's very, very important that you understand at least a little of what it means, how to use them, and how to grow them.
20 Feb, 2009, Skol wrote in the 12th comment:
Votes: 0
Those are really good links. Nice overview and I'd third the suggestion to read them.
21 Feb, 2009, boblinski wrote in the 13th comment:
Votes: 0
Okay, so I started looking at those links.. but I'm already stuck in the very first section…

Quote
Let's be polite and start by saluting the world! Type the following program into your favorite editor:

_____________________________
#include < stdio.h>

void main()
{
printf("\nHello World\n");
}
_____________________________

Save the code in the file hello.c, then compile it by typing:

gcc hello.c


So, I created the file using EditPlus and saved it in C:/ccc as hello.c that part I can do.

Then I go to Cygwin.. change my directory to C:/ccc and type "gcc hello.c" and all I get is:

Quote
Bob@BOB /cygdrive/c/ccc
$ gcc hello.c
hello.c:1:20: stdio.h: No such file or directory
hello.c: In function `main':
hello.c:4: warning: return type of 'main' is not `int'
hello.c:6:2: warning: no newline at end of file
21 Feb, 2009, David Haley wrote in the 14th comment:
Votes: 0
Ah. I guess the tutorial is old enough that main wasn't always supposed to return int. Also, there shouldn't be a space in between the < and the s. I suspect that that's an artifact of conversion to HTML.

Still, even just reading through it and trying to understand what is going on, even without running it, will teach you a lot.

This version should compile cleanly (although I haven't tried it)

#include <stdio.h>

int main()
{
printf("\nHello World\n");
}
21 Feb, 2009, Keberus wrote in the 15th comment:
Votes: 0
boblinski said:
Okay, so I started looking at those links.. but I'm already stuck in the very first section…

Quote
Let's be polite and start by saluting the world! Type the following program into your favorite editor:

_____________________________
#include < stdio.h>

void main()
{
printf("\nHello World\n");
}
_____________________________

Save the code in the file hello.c, then compile it by typing:

gcc hello.c


So, I created the file using EditPlus and saved it in C:/ccc as hello.c that part I can do.

Then I go to Cygwin.. change my directory to C:/ccc and type "gcc hello.c" and all I get is:

Quote
Bob@BOB /cygdrive/c/ccc
$ gcc hello.c
hello.c:1:20: stdio.h: No such file or directory
hello.c: In function `main':
hello.c:4: warning: return type of 'main' is not `int'
hello.c:6:2: warning: no newline at end of file



Okay, Those errors can be broken up.
Quote
hello.c:1:20: stdio.h: No such file or directory


From what you pasted you have a space between < and stdio.h, there should not be one it should be:
#include <stdio.h>



Quote
hello.c:4: warning: return type of 'main' is not `int'


That may be an issue because most Operating Systems expect the program to return different values depending on whether or not there were errors. So, you may want to try:
int main( void )



Quote
hello.c:6:2: warning: no newline at end of file

Perhaps the most simple to fix, just make sure that there is an empty line at the end of the file.


EDIT: Sorry, didn't see DH's reply at first.
21 Feb, 2009, boblinski wrote in the 16th comment:
Votes: 0
okay, managed to create the exe.. but now can't get it to run…

that link says:
Quote
This creates an executable file a.out, which is then executed simply by typing its name.


but where do I type this? and what exactly do I type?


I tried double clicking the a.exe file.. but it popped up with an error:
Quote
a.exe - Unable To Locate Component

X This application has failed to start because gygwin1.dll was not found. Re-installing the application my fix this problem.
21 Feb, 2009, David Haley wrote in the 17th comment:
Votes: 0
You should be running it from your prompt: the same place you compiled from.

Just type: "a.out" or "a.exe". Or, if that doesn't work (it might say file not found) add ./ in front.

(Note that you're working on Cygwin, and these tutorials probably assume Linux proper.)
21 Feb, 2009, Davion wrote in the 18th comment:
Votes: 0
DavidHaley said:
(Note that you're working on Cygwin, and these tutorials probably assume Linux proper.)


You can try AndLinux on 32bit architectures. It's a much more integrated linux console that also includes X. This will most likely solve your problem being outside the Linux OS.
03 Mar, 2009, boblinski wrote in the 19th comment:
Votes: 0
void do_history( CHAR_DATA *ch, char *argument )
{
char buf[MAX_STRING_LENGTH];

if (argument[0] == '?')
{
sprintf(buf,"%s", ch->pcdata->history );
send_to_char(buf,ch);
} else
{
string_append( ch, &ch->pcdata->history );
}
return;
}


Alright, I'm just trying to understand this a little better so I can make some adjustments..


could someone please explain:
- " ( CHAR_DATA *ch, char *argument ) " on line 1.
- the " [0] " on line 5.
and
- line 11.
03 Mar, 2009, David Haley wrote in the 20th comment:
Votes: 0
Line 1 says that do_history is a function that returns nothing, and takes a pointer to a CHAR_DATA and a pointer to a character as its arguments. In C, a string begins at a memory address character and continuing until a \0, so a char* is to be interpreted as "string" in this case.

Line 5 says take the character at address 'argument', in other words, the 0th (first) character of the string.

Line 11 calls the function string_append with arguments 'ch' and ch->pcdata->history, but I don't know what the function itself does so I can't say more than that.

For understanding how strings work etc., I would strongly recommend reading up on arrays and pointers, and strings in general in C. It's a tricky topic that has lots of gotchas if you don't understand what's actually happening.
0.0/46