----------
> From: Cris Jacobin <jacobin@NETREACH.NET>
> To: CIRCLE@post.queensu.ca
> Subject: [Code] User Counter
> Date: Monday, October 13, 1997 12:17 PM
>
> I'm having some trouble with the folloing function, and would
> appreciate some assistance with it.
>
> According to my ansi-c primer, the syntax and implementation seem
> to be correct, however the user counter never goes above 2. Anyone see
> something obvious, that I've overlooked?
>
> ______
> void user_cntr(struct descriptor_data *d)
> {
> FILE *uc_fp;
> long u_cnt = 0;
>
> uc_fp = fopen("USRCNT", "r+b");
> if (uc_fp != NULL) {
> fread(&u_cnt, sizeof (long), 1, uc_fp);
> u_cnt ++;
> fwrite(&u_cnt, sizeof (long), 1, uc_fp);
> fclose(uc_fp);
> sprintf(buf, "You are player #%ld to logon since 9/10/97", u_cnt);
> SEND_TO_Q(buf, d); }
> }
read it, then
rewind(uc_fp);
before you write it. otherwise, it writes it to the file pointers position,
which
is sizeof(long) +1, and when you open the file, it is opened at the
beginning
of the file.
> ______
>
> -jac
> ButterMud - telnet://betterbox.net:4000
>
>
> +------------------------------------------------------------+
> | Ensure that you have read the CircleMUD Mailing List FAQ: |
> | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
> +------------------------------------------------------------+
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST