ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why doesn't this print the game time? What am I doing wrong? The last two printf lines in main do not print and when I compile it on my server I get this error:
Code:
1 [main] a 2917 C:\cygwin64\home\Errigour\c src\web server\a.exe: *** fatal error - Internal error: TP_NUM_C_BUFS too small: 50
Hangup
Also I think it is because of the fscanf in load_game_time()
Code:
#include <stdio.h>
const char *days[] = {
"Beuth", // Beginning truth
"Douth", // Doubt truth
"Bejewl", // Believe jewel
"Fevif", // Forever life
"Not" // No hate
};
const char *months[] = {
"Underus\0",
"Dosendris\0",
"Treviator\0",
"Quatrin\0",
"Cincalm\0",
"Seisol\0",
"Setten",
"Ochace",
"Nuavor",
"Dieoon"
};
struct game_time {
unsigned int second;
unsigned int minute;
unsigned int hour;
} gtime;
struct game_date {
unsigned int day;
unsigned int dayofmonth;
unsigned int month;
long long unsigned int year;
}gdate;
void save_game_time(){
FILE *fp;
if ((fp=fopen("time.db", "w")) == 0)
perror("Error saving time.db!");
fprintf(fp, "%u %u %u %u %u %u %llu", gtime.second, gtime.minute, gtime.hour, gdate.day, gdate.dayofmonth, gdate.month, gdate.year );
fclose(fp);
}
void load_game_time(){
FILE *fp;
if ((fp=fopen("time.db", "r")) == 0)
perror("Error loading time.db!");
fscanf(fp, "%u %u %u %u %u %u %llu", gtime.second, gtime.minute, gtime.hour, gdate.day, gdate.dayofmonth, gdate.month, gdate.year );
fclose(fp);
}
int main()
{
char get[3], path[3], http[4];
char request[]="GET tmp http\0";
setbuf(stdout, NULL);
sscanf(request, "%s %s %s", get, path, http);
printf("%s\n", get);
printf("<html lang=\"en\">\n"
"<title>Space</title>\n"
"<head>\n"
"</head>\n"
"<body>\n"
"A pagan says, \"Finally, Hello world!\"<br>\n"
"<image src=\"favicon.ico\" alt=\"favicon.ico\" height=\"25\" width=\"25\">\n"
"<form method=\"post\" action=\"index.html\">\n"
" <label for=\"email\">Username:</label><input type=\"text\" id=\"email\" name=\"email\" value=\"\"><br>\n"
" <label for=\"pass\">Password:</label><input type=\"password\" id=\"pass\" name=\"pass\" value=\"\"><br>\n"
"<input type=\"submit\" value=\"Login\\Create\">\n"
"</form>\n"
"</body>\n"
"</html>\n\0");
printf("Size of char: %d\n", sizeof(char));
printf("Got here 1\n");
save_game_time();
load_game_time();
/* The following two lines do not print */
printf("Got here 2\n");
printf("%d:%d:%d on %s of %s\n", gtime.hour, gtime.minute, gtime.second, days[gdate.day], months[gdate.month]);
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.