maverk
maverk

Reputation: 27

a way to read from the reverse order and ignore a specific amount of characters

I want a program in C to read from a file from a specific portion in reverse order, ignoring a specific number of characters from being printed. For example:

hello world

I want to start reading from world but I want to ignore the first 3 characters and only print wo

#include <stdio.h>

#define CHARACTER -1

int main(){
    FILE *file = fopen("temp.txt", "r");

    fseek(file, -3, SEEK_END);
    char print ;
    fseek(file, print = CHARACTER, SEEK_CUR);


    char buffer[615];
    fscanf(file, "%s", buffer);
    printf("%c", print);
}

Upvotes: 1

Views: 74

Answers (0)

Related Questions