473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

time function not defined?

I am using the following code to try and output the current date and
time in a C program.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// global variables

struct tm *currentTime ;

int main (void) {
char *time ;

time_t time_now = time (NULL) ;

currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function

Anyone know why the time function is not working for me?

Thanks

Greg
Nov 14 '05 #1
6 9705

"Greg" <dj*********@snowboard.com> a écrit dans le message de
news:7e**************************@posting.google.c om...

Hi,

[snipped]
int main (void) {
char *time ;

time_t time_now = time (NULL) ;
Take a closer look at the two lines above and you'll get the answer.
currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function

Anyone know why the time function is not working for me?
Yes, you declared a pointer to a char named time, which *is in conflict with
the name* of the time() function of the standard library.

Regis
Thanks

Greg

Nov 14 '05 #2
"Greg" <dj*********@snowboard.com> wrote in message
news:7e**************************@posting.google.c om...
I am using the following code to try and output the current date and
time in a C program.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// global variables

struct tm *currentTime ;

int main (void) {
char *time ; ^^^^ local redefinition of time
time_t time_now = time (NULL) ; ^^^^ library function is masked
currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function

Anyone know why the time function is not working for me?


The compiler is telling you. See comments above.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 14 '05 #3
Hi, Greg,

You defined a variable " char *time ", which has the same name of the
function time(), hence when you refer the name "time", it actually refers to
the variable "char *time" in that scope.

Huilong
"Greg" <dj*********@snowboard.com> wrote in message
news:7e**************************@posting.google.c om...
I am using the following code to try and output the current date and
time in a C program.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// global variables

struct tm *currentTime ;

int main (void) {
char *time ;

time_t time_now = time (NULL) ;

currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function

Anyone know why the time function is not working for me?

Thanks

Greg

Nov 14 '05 #4
Greg wrote:
I am using the following code to try and output the current date and
time in a C program.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// global variables

struct tm *currentTime ;

int main (void) {
char *time ; ^^^^
You have changed 'time' from referring to a function to referring to a
pointer-to-char.
time_t time_now = time (NULL) ; ^^^^
The pointer-to-char identifier 'time' is not a function name in this scope.

currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function


Obviously. pointers-to-char are not functions.

Nov 14 '05 #5
dj*********@snowboard.com (Greg) writes:
I am using the following code to try and output the current date and
time in a C program.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// global variables

struct tm *currentTime ;

int main (void) {
char *time ;

time_t time_now = time (NULL) ;

currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function

Anyone know why the time function is not working for me?


Several other people have told you that the problem is your
redefinition of "time" as a char* variable. But for future reference,
if you post a code sample and an error message that indicates a line
number, let us know where line 12 really is. The line containing the
call to time() is actually the 13th line of the code you posted.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #6
In <7e**************************@posting.google.com > dj*********@snowboard.com (Greg) writes:
I am using the following code to try and output the current date and
time in a C program.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// global variables

struct tm *currentTime ;

int main (void) {
char *time ;

time_t time_now = time (NULL) ;

currentTime = localtime (&time_now) ;
}

When I compile this I get the following:

time.c: In function `main':
time.c:12: called object is not a function

Anyone know why the time function is not working for me?


In C, object names share the same name space with function names.
When you declared time as a char pointer in main, you have suppressed the
declaration of time coming from <time.h> until the end of the block
containing the new declaration (i.e. until the end of the function main
in your case).

IOW, you have shot yourself in the foot.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
8
by: Chris | last post by:
Sorry, This should be simple, but brain is hurting... How do I convert a Current Time to a Decimal 6,0 (HMS)? There must be a cleaner way then this: Insert into Table Values Dec(...
6
by: DCSudolcan | last post by:
I know that a program can create and properly initialize an array of pointers to functions at build time, but can something like the following be done at build time? void foo(void); unsigned...
11
by: srkkreddy | last post by:
Hi, I have written a large program which makes multiple calls to number of functions (also written by me) of the program. Now, I want to know the collective time taken by all the calls to a...
6
by: Charles M. Reinke | last post by:
I'm using the function clock() to measure the run time of a program so that I can compare among several different algorithms. My code looks like: #include <stdio.h> #include <stdlib.h>...
6
by: SJ | last post by:
howdy, In vb6 I could say If Time >#4:00:00 PM# And Time < #4:01:00 PM# Then 'Do Something End If Well, I don't see the Time function in vb.net. I have experimented with the TimeSpan...
8
by: Antony | last post by:
compiler£ºVisual Studio.Net 2003 (VC7.1) compile type£ºDebug problem: wanted more information about the "Run-Time Check Failure #n",thanks! Example1: #include "stdafx.h" void malice() {...
22
by: Drum2001 | last post by:
I have a table that tracks employee times. I have a column (Date/Time). Users, through a form, enter how long it takes them to complete a task. For example, 03:45 = 3 hours and 45 mins. I am...
17
by: Andrew Chalk | last post by:
Network time uses 1900 as its base. The C time library uses 1970. I want to convert a network time value to a C library time. I.e. I have to subtract the number of seconds from 1900 to 1970. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.