Ik gok er op dat mijn probleem een vrij basis probleem is, en toch heb ik na zoeken op google, c++ websites/forum en got nog geen antwoord kunnen vinden.
Ik ben ook nog niet zo erg ervaren met c++ maar probeer vooral te leren van voorbeelden, die zelf aan de praat te krijgen en aan te passen. Intussen heb ik wel wat basis tutorials gelezen, maar om een of andere reden ben ik nog geen site tegen gekomen waar het gebruik van chars en ints en wat je waarmee mag doen goed wordt uitgelegd.
Ik zit met de volgende code:
In de main loop gebeurt niet zo heel veel spannends, dat gaat ook prima. Het gaat mis bij de functions onderaan.
Hij geeft errors op de lijnen 29, 93, 94, 124, 125, 134, 135 en 136, allemaal dezelfde fout:
Er zit dus iets goed fout in de "strcpy" en de "sprintf".
Ik begin het onbegrip bij mezelf voor die chars goed zat te worden
Is er iemand die me hiermee verder kan helpen?
Ik ben ook nog niet zo erg ervaren met c++ maar probeer vooral te leren van voorbeelden, die zelf aan de praat te krijgen en aan te passen. Intussen heb ik wel wat basis tutorials gelezen, maar om een of andere reden ben ik nog geen site tegen gekomen waar het gebruik van chars en ints en wat je waarmee mag doen goed wordt uitgelegd.
Ik zit met de volgende code:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
| #include "aw.h" #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <fcntl.h> #include <string.h> #include <fstream> #include <iostream> #include <cctype> using namespace std; int rc; char chattext; char chatname; char message; char logtmp; char logfile; void handle_avatar_add (void); void handle_avatar_delete (void); void handle_chat (void); void add_to_file (char message); main (int argc, char *argv[]) { strcpy (logfile, "test.log"); /* check command line */ if (argc < 3) { cout << "Usage: " << argv[0] << " citnum privpass world" << endl; exit (1); } /* initialize Active Worlds API */ if (rc = aw_init (AW_BUILD)) { cout << "Unable to initialize API (reason " << rc << ")" << endl; exit (1); } /* install handler for avatar_add event */ aw_event_set (AW_EVENT_AVATAR_ADD, handle_avatar_add); aw_event_set (AW_EVENT_AVATAR_DELETE, handle_avatar_delete); aw_event_set (AW_EVENT_CHAT, handle_chat); /* create bot instance */ if (rc = aw_create ("aw.l3d.nl", 5670, 0)) { cout << "Unable to create bot instance (reason " << rc << ")" << endl; exit (1); } /* log bot into the universe */ aw_int_set (AW_LOGIN_OWNER, atoi (argv[1])); aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, argv[2]); aw_string_set (AW_LOGIN_APPLICATION, "L3D-lode-logbot"); aw_string_set (AW_LOGIN_NAME, "ChatBot"); if (rc = aw_login ()) { cout << "Unable to login (reason " << rc << ")" << endl; exit (1); } /* log bot into the world */ if (rc = aw_enter (argv[3])) { cout << "Unable to enter world (reason " << rc << ")" << endl; exit (1); } /* announce our position in the world */ aw_int_set (AW_MY_X, 1000); /* 1W */ aw_int_set (AW_MY_Z, 1000); /* 1N */ aw_int_set (AW_MY_YAW, 2250); /* face towards GZ */ if (rc = aw_state_change ()) { cout << "Unable to change state (reason " << rc << ")" << endl; exit (1); } /* main event loop */ while (!aw_wait (-1)) ; /* close everything down */ aw_destroy (); aw_term (); return 0; } void handle_avatar_add (void) { strcpy (chatname, aw_string (AW_AVATAR_NAME)); sprintf (message, "\t[enter: %s]", chatname); add_to_file (message); /* log the event to the console */ cout << "\t[enter: " << chatname << "]" << endl; } void handle_avatar_delete (void) { strcpy (chatname, aw_string (AW_AVATAR_NAME)); sprintf (message, "\t[leave: %s]", chatname); add_to_file (message); /* log the event to the console */ cout << "\t[leave: " << chatname << "]" << endl; } void handle_chat (void) { strcpy (chatname, aw_string (AW_AVATAR_NAME)); strcpy (chattext, aw_string (AW_CHAT_MESSAGE)); sprintf (message, "%s:\t%s", chatname, chattext); add_to_file (message); /* log the event to the console */ cout << chatname << ":\t" << chattext << endl; } void add_to_file (char message) { ofstream add_to_file ("test.log", ios::app); if (!add_to_file.is_open()) { cout << "logfile \"test.log\" can't be opened \n"; add_to_file.close(); exit (1); } else { add_to_file<<message; add_to_file<<"\n"; add_to_file.close(); } } |
In de main loop gebeurt niet zo heel veel spannends, dat gaat ook prima. Het gaat mis bij de functions onderaan.
Hij geeft errors op de lijnen 29, 93, 94, 124, 125, 134, 135 en 136, allemaal dezelfde fout:
code:
1
| error: invalid conversion from `char' to `char*' |
Er zit dus iets goed fout in de "strcpy" en de "sprintf".
Ik begin het onbegrip bij mezelf voor die chars goed zat te worden
Is er iemand die me hiermee verder kan helpen?
[ Voor 11% gewijzigd door CyberArt op 12-08-2005 02:12 . Reden: line# 50 moest line#29 zijn ]
hopende hiermee een post te hebben gemaakt, teken ik