I want to designe a code at display a perticular data Example a time table of the week
For instance if someone view a page on monday so it show display result of the table or data which is set to display on monday
or if some one view same page of tuesday it should get other data which is set to display only on tuesdays
and it should also be flexsible such as if some one had to view tuesdays timetable on monday he just had to select the date as result should appear

If any one had any idea it would be a greate help...
Thanxx in advance

Recommended Answers

All 5 Replies

All you have to do is call time() function (see time.h) to get current computer system time and date. Then you could have the data stored in files with the filename of the date it was written (you would want to include time if time of day is important). For example the filename could be "2013-3-24.txt" If you want the data for a specific date just format the filename with the given date.

Another way to do it is to have all the data in one file and date/time stamp each record. You didn't mention what kind of data you are talking about, so assume one row if the file for any given date/time. The time could look much like an Excel spreadsheet where columns are separated with commas or some other character.

Assuming this as the data store in of of the txt file names a timetable.txt
So how should I extract the data from the file when of the particular day
suppose I want the data of tuesday what command should I use for it to
display that data on screen I use a seperator ";" to distinguish data

        Time table
    ------------------
    monday   ;   Tuesday  
1.  Subject1 ;   subject2
2.  subject2 ;   subject1
3.  subject4 ;   subject3
4.  subject3 ;   subject4

As the output should display as if open on tuesday

Today day is Tuesday,dd/mm/yyyy
______________________________
Time table for Tuesday:
------------------------------
1.subject2
2.Subject1
3.subject3
4.subject4

If the columns are always in the order you posted, then after reading a line the data for Tuesday immediately follows the first semicolon. You can locate the position of the first semicolon by calling the function strrchr() (string.h). That function will return a pointer to the first occurrence of the semicolon (or some other character you specify).

beginning of loop

read a line
find position of first semicolon
increment the pointer returned by strrchr() by one to bypass the semicolon
now increment the pointer some more until the first non-space chacracter is reached
The pointer is now at the beginning of the data for Tuesday
Copy the data somewhere else to keep it for later printing or just print it on the screen

end of loop

The text documnet conatins the string starting with number represinding a week of the dayi.e 1-monday
2-tuesday,3-wednusday......so on.

TEXT DOCUMENT "t.txt":

1subject1;subject2;subject3
2subject2;subject1;subject3
3subject3;subject2;subject1
4subject1;subject3;subject2
5subject3;subject2;subject3
6subject2;subject1;subject3
0subject1;subject3;subject3

Code:

#include<stdio.h>
#include<conio.h>
#include <string.h>
#include<time.h>

void main()
{
    char msg[100];
    char c=';';
    int i,k;

//Time Function Starts//

    time_t now;                      //time block
    struct tm *d;                    //time block
    char li[13];                     //time block
    time(&now);                      //time block
    d = localtime(&now);             //time block
    strftime(li, 15, "%w", d);       //time block
    printf("%s\n", li);
    char b;
    b=li;//Copying the value li in variable b for comparation
//Time Function  Ends//

//File Function Starts//

    FILE *fp;                   //Declare file variable
    fp=fopen("t.txt","r");      //Open file
    while(!feof(fp))            //Print the charaters of the file till EOF
    {
        fgets(msg,100,fp);      //Get String from fp and store in msg of siz 100 character
        if(msg[0]==b)           //compare the first character of the string with li if the character is match it prints the line of that text
        {
            i=strlen(msg)-1;   //calculate the size of character in msg-1
            if(msg[i]=='\n')   //If any new line charater found.
            {
                msg[i]='\0';   //if any new line chacter forund is replace by \0
            }
            for(k=0; k<=i; k++)
            {
                if(msg[k]==';') //If any ';' charater found is replaced by a new line.
                {
                    msg[k]='\n';
                }
            }
            puts(msg);         //Dispaly the string store in msg
            i=strlen(msg);     //Again counts the character in msg
        }
    }
    fclose(fp);               //Close the file

//File Ends//
}

Which one is perfect this code or the previous code..At last some how I figure atlest a bit to get the desired result.

#include<stdio.h>
#include<conio.h>
#include <string.h>
#include<time.h>
#include<stdlib.h>

void main()
{
char msg[100];
int i,k,t,st;
FILE *fp;   //Declare file variable
//Time Function Starts//

time_t now;                       //time block
struct tm *d;                     //time block
char li[13];                      //time block
char day[13];
time(&now);                       //time block
d = localtime(&now);              //time block
strftime(li, 15, "%w", d);        //time block
t=atoi(li);                         //convert string to int
strftime(day, 15, "%A", d);
//Time Function  Ends//

//File Function Starts//
printf("-----------------------------\n");
printf("  Time Table for: %s\n",day);
printf("-----------------------------\n");
fp=fopen("t.txt","r");  //Open file
while(!feof(fp))    //Print the charaters of the file till EOF
{
    fgets(msg,100,fp); //Get String from fp and store in msg of siz 100 character
    st=atoi(msg);       //convert string to int
    if(st==t)
    {
        i=strlen(msg)-1;   //calculate the size of character in msg-1
        for(k=0;k<=i;k++)
        {
        msg[k]=msg[k+1];
        }
        i--;
        if(msg[i]=='\n')   //If any new line charater found.
        {
            msg[i]='\0';     //if any new line chacter forund is replace by \0
        }
        for(k=0;k<=i;k++)
        {
            if(msg[k]==';')   //If any ';' charater found is replaced by a new line.
            {
            msg[k]='\n';
            }
        }
        puts(msg);         //Dispaly the string store in msg
    }
}
printf("-----------------------------\n");
fclose(fp);        //Close the file

//File Ends//
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.