Well I am ashamed to say this ...but in all the time I am writing programs in C I always used data etc...directly from files. So I basically don't know how to put user input...I've checked some previous posts and tutorials but I can't really see what's wrong...the program works fine without the red part
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int linesoffilex(FILE *estream)
{
fseek(estream, 0, SEEK_SET);
char mb[8];
char* forpop = "%7s\n";
int j=0;
while (fscanf (estream, forpop, mb) == 1)
{
j++;
}
return j;
}
int main ()
{
time_t timer;
struct tm *tm_now;
char filtime[BUFSIZ];
char name[2];
timer = time(NULL);
tm_now = localtime (&timer);
printf("press 1. to open a previous month or\n ANY key for current month\n");
fgets(name, 1, stdin);
if (name == "1")
{
printf("enter full file name\n");
fgets(filtime, 12, stdin);
}
else
{
strftime (filtime , sizeof filtime, "%b %Y.txt", tm_now);
}
FILE *astream;
astream = fopen(filtime, "a");
fclose(astream);
FILE *bstream;
bstream = fopen(filtime, "r");
int j, g, k;
j = linesoffilex(bstream);
double *kb;
kb = malloc(sizeof(double)*j);
fseek(bstream, 0, SEEK_SET);
char * del = "%lf\n";
for (g = 0; g < j; g++)
{
fscanf(bstream, del, &kb[g]);
}
double sum;
for (k = 0; k < j; k++)
{
sum = kb[k]+sum;
}
fclose(bstream);
FILE *cstream;
cstream = fopen("statistics.txt", "w");
fprintf(cstream, "Total kb so far: %lf\n",sum);
fprintf(cstream, "Total kb remaining: %lf\n",3000-sum);
fprintf(cstream, "Next day estimated usage: %lf\n",sum/j);
fprintf(cstream, "Monthly estimated usage: %lf\n",(sum/j+1)*31);
fprintf(cstream, "Daily recommented usage: %lf\n",(3000-sum)/(31-j));
fclose(cstream);
return 0;
}
What it does is that is exiting before the user inputs anything