not sure what your issue is - you could do this (separate file handle for reading and writing) :-
#include <stdio.h>
main()
{
int t_size;
FILE *fp_read;
fp_read = fopen ("xxx.txt", "r");
fscanf(fp_read, "%d", &t_size);
fclose(fp_read);
FILE *fp_write;
int a = 1;
fp_write = fopen("test.txt", "w+");
fprintf(fp_write, "The int is %d\n", a);
fclose(fp_write);
}
that makes your code slightly easier to read - or you could simply close and then re-use the file handle :-
main()
{
FILE *fp;
int t_size;
fp = fopen ("xxx.txt", "r");
fscanf(fp, "%d", &t_size);
fclose(fp);
int a = 1;
fp = fopen("test.txt", "w+");
fprintf(fp, "The int is %d\n", a);
fclose(fp);
}
btw, no-where in your code do you show handling for end-of-file / error conditions