0
I’ve created a structure that holds three records of any kind. These records I read from an f file. They have a set size, in the case below the first dice has three characters, the second 17 and the third three. I used it because the data may come anyway, but the default is guaranteed. Example inside the f file:
999 Eduardo Oliveira SI
111EduardoOliveira SI (Two spaces before SI, could not put here)
for (i = 0; i < qtde_registros; i++)
{
fscanf(f,"%3s",rt[i].m);
rt[i].m[3]='\0';
fscanf(f,"%17c",rt[i].n);
rt[i].n[17]='\0';
fscanf(f,"%3c",rt[i].c);
rt[i].c[3]='\0';
}
It is working perfectly, the problem is that I do not want to leave this fixed size, I want to get the size of each of the three data with the user or by another file. How can I replace these number "3,17,3" with variables. Example of what I want:
int tamPrimeiroDado=3;
int tamSegundoDado=17;
int tamTerceiroDado=3;
for (i = 0; i < qtde_registros; i++)
{
fscanf(f,"% >>AQUI(tamPrimeiroDado)<< s",rt[i].m);
rt[i].m[tamPrimeiroDado]='\0';
fscanf(f,"% >>AQUI(tamSegundoDado)<< c",rt[i].n);
rt[i].n[tamSegundoDado]='\0';
fscanf(f,"% >>AQUI(tamTerceiroDado)<< c",rt[i].c);
rt[i].c[tamTerceiroDado]='\0';
}
With one or more 'for', 'fseek', 'fgetc' ... I get what I want, but is there any way to do this with C data masks? Thank you.