2011年4月13日 星期三

fseek - change file pointer

#include <stdio.h>
echo 1 > /home/ubuntu/1test.txt

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

int main () 
{
    FILE *fp;
    char buffer[1];
    int ret=0;
 
    fp = fopen("/home/ubuntu/1test.txt", "r");
    while(1)
    {
        fseek(fp, -1, SEEK_CUR);
        fread(buffer, 1, 1, fp);
        fseek(fp, 0, SEEK_CUR);
        printf("%s, %d\n", buffer, ret);
    }
    fclose(fp);
    
    return(0);
}

#!/bin/sh

while true
do
    cat /home/ubuntu/1test.txt
    sleep 0.2
done

ref: Here

沒有留言:

張貼留言