请教各位大虾关于TIME()函数在C语言的用法

westlifezs 2008-08-29 07:23:41
小弟遭遇编程难题,老师让看一个代码,居然编译通不过,很是苦恼,请教大家!

以下是源代码,编译时总是告诉我有错误,总是说“time_t”: 将此类型用作表达式非法”,问题之处我已经标识了绿色,希望大虾们帮小弟解答一下这个问题,再次感谢!
#ifndef _TIME_T_DEFINED
typedef long time_t; /* 时间值 */
#define _TIME_T_DEFINED /* 避免重复定义 time_t */
#endif
#include <stdio.h>
#include <time.h>
#include <string.h>




FILE *scorefile;
int get_score(char *name, char *ssn, char *score);
char* str_prefix(char *prefix, char *str);

int main(int argc, char *argv[])
{
int ruid, euid;
char score[128];

if (argc != 3) {
printf("Usage: getscore name SSN\n");
exit(1);
}

time_t current_time = time(NULL);
ruid = getuid ();
euid = geteuid ();
// This is to make sure the logging command will have
// sufficient privilege.
if (setreuid(euid, euid)){
perror("setreuid");
}

scorefile = fopen("score.txt", "r");
if (scorefile == NULL){
printf ("failed to open score file\n");
}
else{
if (get_score(argv[1], argv[2], score)){
char command[256];
printf("Invalid user name or SSN.\n");
sprintf(command, "echo \"%s: Invalid user name or SSN: %s,%s\"|cat >> error.log",
ctime(¤t_time), argv[1], argv[2]);
if (system(command)){
perror("Logging");
}
exit(-1);
}
printf("Your score is %s\n", score);
}
}

int get_score(char *name, char *ssn, char *score)
{
char matching_pattern[128];
char line[128];
char *match_point;

strcpy(matching_pattern, name);
strcat(matching_pattern, ":");
strcat(matching_pattern, ssn);

while (fgets(line, 128, scorefile)!=NULL){
if (match_point=str_prefix(matching_pattern, line)){
if (*match_point++==':'){
while (*match_point!=':'){
*score++=*match_point++;
}
*score=0;
return 0;
}
}
}

return -1;
}

char* str_prefix(char *prefix, char *str){
while (*prefix && *str){
if (*prefix != *str)
return NULL;
prefix++;
str++;
}
return *prefix==0?str:NULL;
}

...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
westlifezs 2008-08-29
  • 打赏
  • 举报
回复
ding
westlifezs 2008-08-29
  • 打赏
  • 举报
回复
谢谢你回复,你是说把绿色的那句放到char score[128]; 后面么?
我试了一下,还是不行啊,怎么回事儿呢?希望有更多的人能帮助我下,谢谢
chengng 2008-08-29
  • 打赏
  • 举报
回复
你是用C编译器,将这句放到char score[128]; 后面
westlifezs 2008-08-29
  • 打赏
  • 举报
回复
谢谢楼上的,可是我去掉之后编译还是错误的,怎么回事儿呢?我原来的头文件里面是如下信息:
#ifndef _TIME_T_DEFINED
#ifdef _USE_32BIT_TIME_T
typedef __time32_t time_t; /* time value */
希望大虾能继续帮助我一下,谢谢
菜牛 2008-08-29
  • 打赏
  • 举报
回复
time_t在time.h文件中有定义,把你自己的typedef那句去掉。
westlifezs 2008-08-29
  • 打赏
  • 举报
回复
小弟新人,没什么积分,实在不好意思,若有幸得大侠帮助,日后定当感激不尽

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧