i have just built a program that reads a data from a file named "text.txt" and parse it through JSON as i know the size of a file that im reading character wise so in for loop i have defined the value of i in for loop as 647, pleas help me if the value increases or decreases then how would i manage it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "jsmn.h"
void error(char *msg)
{
      perror(msg);
      exit(0);
}
static int jsoneq(const char *json, jsmntok_t *tok, const char *s)
{
    if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && strncmp(json + tok->start, s, tok->end - tok->start) == 0)
    {
        return 0;
    }
    return -1;
}
int main(int argc, char const *argv[])
{ 
    int i,n,r;
    char buf[1024];
    char JSON_STRING[5000];
    jsmn_parser p;
    jsmntok_t t[2048];
    char * fname;
    FILE *fp=fopen("text.txt","r+");
    FILE *ff;
    if(fp==NULL)
    {
        error("file opening error");
    }
    for(int i=0; i<647;i++)   /////////this if the for loop //////////
    {
        JSON_STRING[i] = getc(fp);
    }
    jsmn_init(&p);
    r = jsmn_parse(&p,JSON_STRING,  strlen(JSON_STRING), t,     sizeof(t)/sizeof(t[0]));
    if (r < 0){
        printf("\nFailed to parse JSON: %d\n", r);
        return 1;
    }
    else{
        for (i = 1; i < r; i++){
            if (jsoneq(JSON_STRING, &t[i], "RID") == 0)
            // for extracting the value of Rid from the complete string 
            {/* We may use strndup() to fetch string value */
            //printf("RID: '%.*s'\n",t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start);
            printf("- RID: %.*s\n", t[i+1].end-t[i+1].start,JSON_STRING + t[i+1].start);
            sprintf(fname,"%.*s",t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start);
            ff=fopen (fname, "w");
            fprintf(ff, "RID: '%.*s'\n",t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start );
            i++;
        }
    }
    else if (jsoneq(JSON_STRING, &t[i], "DID") == 0)    //for Extracting the value of DID from te string recived from the client JSON_STrING
    {
        /* We may additionally check if the value is either "true" or "false"*/
        printf("- DID: %.*s\n", t[i+1].end-t[i+1].start,JSON_STRING + t[i+1].start);
        fprintf(ff, "DID: '%.*s'\n",t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start );
        i++;
        //sprintf(fname,"%s_%.*s",fname,t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start); 
    }
    else if (jsoneq(JSON_STRING, &t[i],"TS") == 0)
    {
        /* We may want to do strtol() here to get numeric value */
        printf("- TS: %.*s\n", t[i+1].end-t[i+1].start,JSON_STRING + t[i+1].start);
        fprintf(ff, "TS: '%.*s'\n",t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start );
         // sprintf(fname,"%s_%.*s",fname,t[i+1].end - t[i+1].start, JSON_STRING+ t[i+1].start);
    }
    /*  else
    {
    printf("Unexpected key: %.*s\n", t[i].end-t[i].start,JSON_STRING + t[i].start);}*/
    }
        printf("JSON parsed : %d\n", r);
        printf("output have been generated to the file");
        fprintf(ff, "%s\n",JSON_STRING );
        fclose(ff);
    }
    return EXIT_SUCCESS;
    fclose(fp);
    return 0;
}
 
     
     
    