Hello!
I want to read a file with a specific text format to a struct (or array of structs...) and than write it to a new file.
The text format of the file is:
{int}{int}string\n
Some example lines:
{12}{34}The text i want
{56}{105}More and more text
This is parte of my code:
typedef struct
{
int num1;
int num2;
char text[100];
} Format;
while(!f_in)
{
fscanf(f_in,"{%d}{%d}%[^\n]\n", &Format->num1, &Format->num2, Format->text);
// then i change the num1 and num2
fprintf(f_out,"{%d}{%d}%s\n",Format->num1,Format->num1,Format->text);
}
Using this code i have a big problem: when i declare char text[100] i´m puting the limit in 100 char but i don´t want the text has a limit. What sould i do?
Other thing...instead of read a line change the numbers and then write the line in the other file i want to read all the lines of the input file to a array of structs (struct like the one i define above). But here i bave other problem, how can i defien a array o structs with no limit (because i don't know the number of lines th file has). What you sugest?
If you have any other sugestion to read the file and get the imformation it has (i heard fscanf is not very good) please tell me.
I want to read a file with a specific text format to a struct (or array of structs...) and than write it to a new file.
The text format of the file is:
{int}{int}string\n
Some example lines:
{12}{34}The text i want
{56}{105}More and more text
This is parte of my code:
typedef struct
{
int num1;
int num2;
char text[100];
} Format;
while(!f_in)
{
fscanf(f_in,"{%d}{%d}%[^\n]\n", &Format->num1, &Format->num2, Format->text);
// then i change the num1 and num2
fprintf(f_out,"{%d}{%d}%s\n",Format->num1,Format->num1,Format->text);
}
Using this code i have a big problem: when i declare char text[100] i´m puting the limit in 100 char but i don´t want the text has a limit. What sould i do?
Other thing...instead of read a line change the numbers and then write the line in the other file i want to read all the lines of the input file to a array of structs (struct like the one i define above). But here i bave other problem, how can i defien a array o structs with no limit (because i don't know the number of lines th file has). What you sugest?
If you have any other sugestion to read the file and get the imformation it has (i heard fscanf is not very good) please tell me.