WTF ... IS WTF!?
We are a collective of people who believe in freedom of speech, the rights of individuals, and free pancakes! We share our lives, struggles, frustrations, successes, joys, and prescribe to our own special brand of humor and insanity. If you are looking for a great place to hang out, make new friends, find new nemeses, and just be yourself, WTF.com is your new home.

C Compiler Error

32
8
72
#1
Well I was going through a C book to learn C, and one of there examples gave me an error I was wondering if it was me or the example.. attempted to compile it in Dev/Cpp

#include <time.h>
#include <stdio.h>
main ()
{
float var = time();
/*prints current time*/
printf(var);

}


Compiler Error:
c:/dev-cpp/ugh.cpp: In function `int main()':
C:\DEV-C_~1\Include\time.h:96: too few arguments to function `time_t time(time_t *)'
c:/dev-cpp/ugh.cpp:5: at this point in file
c:/dev-cpp/ugh.cpp:7: argument passing to `const char *' from `float'

this script is supposed to display the current time.
 

Fire_ze_Missles

Martha Fuckin' Stewart
1,622
5
38
#2
I see a couple of errors. I don't know C, but some C#, and I have to figure that they are the same, sorta.

The main entry point for a program in C# always starts like this:

public static void Main() {...}

So, I think you need something like that.

Secondly, judging by the error, c:/dev-cpp/ugh.cpp:7: argument passing to `const char *' from `float', the compiler cannot implicintly change case, and therefore, you have to do it by some means; ie. printf(var.toString());.

Hope some of that helps, if not, I tried. :)
 

BRiT

CRaZY
Founder
11,657
2,401
487
#3
This is due to trying to invoke Win32-specific functions while including POSIX style headers.
 

Broken

Member smoked too much weed!
3,891
0
0
#4
BRiT said:
This is due to trying to invoke Win32-specific functions while including POSIX style headers.
Bah~ include the header first. That is all.
 

ThomConspicuous

Inconspicuously Informal
93
0
0
#5
Try this:

#include <time.h>
#include <stdio.h>
main ()
{
time_t now;
time(&now);
/*prints current time*/
printf(now);
}

Or more efficiently:

#include <time.h>
#include <stdio.h>
main ()
{
time_t now;
/*prints current time*/
printf("The current time is:\t\n", time(&now));
}

It's been a long time since I've messed with C, so let me know if this works. Try googling for C time function...many resources and some related to what you are trying.
 

Blaze Daily

<b>Banned - What an Asshat!</b>
146
0
0
#6
http://www.cgd.ucar.edu/cas/software/sysdate.c.html
time_t curtime;
/* type defintion time_t is equivalent to long int */

curtime = time(NULL);
/* Return current time */
Here is some code snippits from the URL at the top.

I think if you define the variable for time, then fill a variable with the FUNCTION 'time(NULL);' then convert the variable to a string you will be able to echo it.

Keep with C, it's a very rewarding language to learn.
 

ThomConspicuous

Inconspicuously Informal
93
0
0
#7
Going along with what Blaze said, check this site out
http://www.randombots.com/time_function.htm

Excellent examples of the many ways you can manipulate time functions.

Some new headers to play with too.

#include <sys/types.h>
#include <sys/timeb.h>

If you are wanting string functionality don't forget
#include <string.h>
 

Jung

???
Premium
13,979
1,397
487
#8
BRiT said:
This is due to trying to invoke Win32-specific functions while including POSIX style headers.
I'm pretty sure <whatever.h> will still compile in DevC++ since it uses GCC. For Windows stuff I think you need to use #include<time> though.

His code was fucked though.

[atreides ~]$ gcc -Wall phantom.c -o phantom
phantom.c:4: warning: return-type defaults to `int'
phantom.c: In function `main':
phantom.c:5: too few arguments to function `time'
phantom.c:7: incompatible type for argument 1 of `printf'
phantom.c:9: warning: control reaches end of non-void function
[atreides ~]$
 
32
8
72
#9
Blah, so the examples were bad? Thats all I really needed to know. /me throws the book out
 

BRiT

CRaZY
Founder
11,657
2,401
487
#11
junglizm said:
His code was fucked though.
Ah, I just figured since it wasn't a POSIX-method invocation that it must have been some WinOS specific method. Didn't think that the provided code was just bunk...