Hi, I'm relatively new to C and extremely new to pointers. I use Dev-C++ as my IDE and when I compile my program I get warnings such as "[Warning] passing arg 1 of `printf' makes pointer from integer without a cast ". The thing is, I don't get this error if I simply open the IDE and instantly press "compile" but I do get it if, say, the printf() line was commented before and then I remove the comment, with the final code being identical. I'm guessing that I'm doing something wrong with pointers. Here's the program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
FILE *outfile;
outfile = fopen("output.txt","w");
if(!outfile)
{
puts("Oh noes!");
exit(0);
}
time_t rawtime = time(NULL);
printf(mlTimeString(&rawtime));
fprintf(outfile, mlTimeString(&rawtime));
fclose(outfile);
return 0;
}
char *mlTimeString(time_t* t)
{
int k, k1;
char* retstring = malloc(30);
if(retstring == NULL) return NULL;
for(k = 0; k < 30; k++)
retstring[k]='\0';
char weekdays[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char months[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
struct tm* readabletime;
readabletime = localtime(t);
int x = (*readabletime).tm_wday;
for(k = 0; weekdays[x][k] != '\0'; k++)
retstring[k] = weekdays[x][k];
k1 = k;
retstring[k1]=',';
retstring[++k1]=' ';
x = (*readabletime).tm_mon;
k1++;
for(k = 0; months[x][k] != '\0'; k++, k1++)
retstring[k1] = months[x][k];
return retstring;
}
The basic idea is that it find the date then mlTimeSTring returns a string with the date formatted in a more readable form. Thanks in advance.