Question: I have the following variables:

```
int year = 2013;
int month = 04;
int day = 07;
int hour = 13;
int min = 42;
int sec = 00;

```

...and I need to extract the "epoch" time, or unix time, from them.

How can this be done in standard C?
In this case, the unix time should be: [1365342120](http://www.epochconverter.com/).

Answer: 
Following technique in C can be useful to read a file like I have shown below, Is this what you wants? 

while EOF not reach: 

* first read 4 chars in first buffer, and unused
* read number in a line, using `fscanf()`, `%d`
* read `\n`
* print number

The file is like: 

```
$ cat file
12345678
98765432
45678324
98653223

```

And code is (read comments):

```
#include<stdio.h>
#include<stdlib.h>
int main(){
    FILE* fp = fopen("file","r");
    char first[5];
    int second;
    while(!feof(fp)){          //  While EOF loop runs   
     fgets(first, 5, fp);      //  read first 4 chars in a line
     fscanf(fp,"%d",&second);  //  Read next 4 digits in 
     fgetc(fp);                //  read \n
     printf("%d\n",second);
    }
    return EXIT_SUCCESS;
}

```

it runs like:

```
:~$ ./a.out 
5678
5432
8324
3223

```
It is an interesting question, and I am not a C expert. I just leave my solution.  

Although I am using "getline" function in the codes below, I will vote for "sscanf".
But "sscanf" is often used for taking out particular elements from a string(like numbers divided by slash, backslash or dot), @Toesmash 's question is to read from specific position, which is nothing to do with the content. You got to consider if such a simple task is worth it.  
So maybe "getline" is simple and good enough. That's my thought.

```
int main()
{
    FILE * fp;
    char * line = NULL;
    size_t len = 0;
    ssize_t read;

    if ((fp = fopen("sample.txt", "r")) == NULL )
    {
        /* do your error process */
    }

    while((read = getline(&line, &len, fp)) != -1)
    {
        /* you see here offset is 5, if you want the last 4 characters */
        printf("%s", (line + (read - 5)));
    }

    return 0;
}

```

The good thing is, you got everything you need, the pointer to head, the length, etc.  

The bad thing is, I read the whole line, which is maybe unnecessary :)