English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
La funzione fseek() viene utilizzata per impostare il puntatore di file su un offset specificato. Serve per scrivere dati nel file nella posizione desiderata.
Sintassi:
int fseek(FILE *stream, long int offset, int whence)
Il primo parametro stream è il puntatore di file
Il secondo parametro offset è l'offset, un numero intero rappresenta un offset positivo, un numero negativo rappresenta un offset negativo
Il terzo parametro whence determina da dove iniziare a offsettare, può utilizzare uno dei tre valori costanti, che possono essere: SEEK_CUR, SEEK_END o SEEK_SET
SEEK_SET - Inizio del file
SEEK_CUR - Posizione corrente
SEEK_END - Fine del file
Verranno utilizzati in successione SEEK_SET, SEEK_CUR e SEEK_END per rappresentare 0, 1 e 2 rispettivamente.
#include <stdio.h> void main(){ FILE *fp; fp = fopen("myfile.txt","w+"); fputs("Questo è oldtoolbag.com", fp); fseek(fp, 7, SEEK_SET); fputs("Seagull Ali", fp); fclose(fp); }
myfile.txt
Questo è Seagull Ali