- 主题:实现查询大于指定天数未上线用户功能遇到的问题
我编写的程序如下:(在libBBS/ucache.c中,在头文件中声明了的)
int searchunday(long daynum)
{
int j;
FILE *fp,*fpp;
struct userec user;
fpp =fopen("/usr/local/bbs/.PASSWDS","rb");//安装目录
fp =fopen("/home/bbs/result.txt","a+");
if(fp=NULL)return 0;
j =0;
while(!feof(fpp))
{ fread(&user, sizeof(user), 1, fpp);
if((time((time_t *)NULL)-user.lastlogin)/(24*60*60)>=daynum)
{
fwrite(&user,sizeof(user),1,fp);
j=j+1;
}
}
fclose(fp);
fclose(fpp);
return j;
}
在phplib/phpbbs.user.c中加了:
PHP_FUNCTION(bbs_getunday)
{
long s;
long num;
if (zend_parse_parameters(1 TSRMLS_CC, "l", &s) != SUCCESS) {
WRONG_PARAM_COUNT;
}
num =searchunday(s);
RETURN_LONG(num);
}
在phplib/phpbbs.user.h中加了:
PHP_FUNCTION(bbs_getunday);
PHP_FE(bbs_getunday, NULL) \
但是调用的时候出现问题,函数是可以调用的,因为那个result.txt文件创建了,但是里面没有内容,而且在php代码中调用bbs_getunday没有返回值,是怎么回事啊!大家帮忙分析一下.
--
FROM 202.115.30.*
没判断user.userid[0]是不是\0
你确定result.txt是空文件?还是最开始有很多空行?
【 在 pplong2000 (hiker) 的大作中提到: 】
: 我编写的程序如下:(在libBBS/ucache.c中,在头文件中声明了的)
: int searchunday(long daynum)
: {
: int j;
: FILE *fp,*fpp;
: struct userec user;
: fpp =fopen("/usr/local/bbs/.PASSWDS","rb");//安装目录
: fp =fopen("/home/bbs/result.txt","a+");
: if(fp=NULL)return 0;
: j =0;
: while(!feof(fpp))
: { fread(&user, sizeof(user), 1, fpp);
: if((time((time_t *)NULL)-user.lastlogin)/(24*60*60)>=daynum)
: {
: fwrite(&user,sizeof(user),1,fp);
: j=j+1;
: }
: }
: fclose(fp);
: fclose(fpp);
: return j;
: }
: 在phplib/phpbbs.user.c中加了:
: PHP_FUNCTION(bbs_getunday)
: {
: long s;
: long num;
: if (zend_parse_parameters(1 TSRMLS_CC, "l", &s) != SUCCESS) {
: WRONG_PARAM_COUNT;
: }
: num =searchunday(s);
: RETURN_LONG(num);
: }
: 在phplib/phpbbs.user.h中加了:
: PHP_FUNCTION(bbs_getunday);
: PHP_FE(bbs_getunday, NULL) \
: 但是调用的时候出现问题,函数是可以调用的,因为那个result.txt文件创建了,但是里面没有内容,而且在php代码中调用bbs_getunday没有返回值,是怎么回事啊!大家帮忙分析一下.
--
FROM 128.12.150.*
[bbs@raid test]$ cat unday.c
#include "bbs.h"
static int searchunday(struct userec *user, void* arg) {
int d = (int)arg;
if (user->userid[0] && (time(NULL) - user->lastlogin)>=d*86400) {
printf("%s\n",user->userid);
}
return 0;
}
int main(int argc, char** argv) {
int d;
if (argc != 2) return 0;
d = atoi(argv[1]);
init_all();
apply_users(searchunday, (void*)d);
}
[bbs@raid test]$ alias kgcc
alias kgcc='gcc -I/home/bbs/src/build -I/home/bbs/src/kbs_bbs/src -I/usr/include/mysql -lBBS -lsystem -L/home/bbs/lib'
[bbs@raid test]$ kgcc unday.c -o unday
[bbs@raid test]$ ./unday 100
SYSOP
【 在 pplong2000 (hiker) 的大作中提到: 】
: 我编写的程序如下:(在libBBS/ucache.c中,在头文件中声明了的)
: int searchunday(long daynum)
: {
: ...................
--
FROM 128.12.150.*
init_all()是干嘛的来着
我记得你说过这个函数不能随便加, 位置不好的话就会把整个数据搞坏
【 在 atppp (Big Mouse) 的大作中提到: 】
: [bbs@raid test]$ cat unday.c
: #include "bbs.h"
: static int searchunday(struct userec *user, void* arg) {
: ...................
--
FROM 159.226.37.*
就是,那个函数是什么功能啊?还有atppp大大有没有开发php扩展的经验啊?都有哪几个地方需要更改啊??
--
FROM 202.115.30.*
不敢用
【 在 atppp (Big Mouse) 的大作中提到: 】
: [bbs@raid test]$ cat unday.c
: #include "bbs.h"
: static int searchunday(struct userec *user, void* arg) {
: ...................
--
FROM 221.204.246.*
直接看init_all()函数吧,
用点逆向方法
【 在 jiangjun2000 (%d) 的大作中提到: 】
: init_all()是干嘛的来着
: 我记得你说过这个函数不能随便加, 位置不好的话就会把整个数据搞坏
--
FROM 221.204.246.*