#include <stdio.h> #include <time.h> int main() { time_t sec; sec = time(NULL); printf("Number of hours since January 1, 1970 is %dId /n", sec/3600); return 0; }
The following example shows the usage of rand() function.
#include#include int main() { int i, n; time_t t; n = 5; /* Initializes random number generator */ srand((unsigned) time(&t)); /* Print 5 random numbers from 0 to 49 */ for( i = 0; i < n; i++) { printf("%d\n", rand() % 50); } return(0); }
The most important string functions are as follows:
strlen() Get length of a string.
strcat() Link together (concatenate) two strings.
strcmp() Compare two strings.
strchr() Find character in string.
strstr() Find string in string.
strlwr() Convert string to lowercase.
strupr() Convert string to uppercase.
#include <stdio.h> #include <stdlib.h> int main() { char *t = "XXX"; printf( "Length of <%s> is %d.\n", t, strlen( t )); }