C99 or otherwise, do you really _need_ to know the file size in
advance? Besides getting the data into a buffer (no doubt handy),
what is the larger problem to be solved?
Believe it or not I’m trying to write a "sort of" application layer for
my own implementation of 3 layers of the OSI protocol (TL,NL,DL).
One might think; That's a big step to start programming networks layers
in C if you can't even control basic file handling, and I would be the
to agree with you.
Nevertheless, although I have never before programmed in C it’s the
demand for the assignment at my class that this project is implemented in C.
Well back to the matter at hand:
I think I need the size of the input file, so I can make the buffer I
want to send to the TP layer only the size of the input file.
I’m currently putting the input from the file in to a unsigned char
array, but I have to specify the size of this array when I create it, so
even if my input file only contains say 100 characters, the array is
potential much bigger.
Here is my code so far:
void station_a(void)
{
unsigned char c[MAX_FILE_SIZE];
unsigned char buffer[MAX_FILE_SIZE];
FILE *file;
printf("[TEST METHOD][Station %i] : Station started\n", ThisStation);
printf("[TEST METHOD][Station %i] : Trying to open inputfile\n",
ThisStation);
file = fopen("inputfile.txt", "r");
if(file==NULL)
{
printf("[TEST METHOD][Station %i] : Error: can't open inputfile\n",
ThisStation);
}
else
{
printf("[TEST METHOD][Station %i] : Inputfile opened successfully\n",
ThisStation);
printf("[TEST METHOD][Station %i] : Reading file contens->\n\n\t ");
while(fgets(c, MAX_FILE_SIZE, file)!=NULL)
{
printf("%s", c);
}
printf("\n%i", sizeof(c));
printf("\n%c", c[0]);
/*
int i;
for(i = 0;i < sizeof(c);i++)
{
printf("%s", c
);
}
*/
//printf("\n%s", c[0]);
printf("\n\n");
printf("[TEST METHOD][Station %i] : Sending file\n", ThisStation);
from_user(c,ThisStation,2); //sending to next layer!!
printf("[TEST METHOD][Station %i] : Closing file\n", ThisStation);
fclose(file);
}
printf("[TEST METHOD][Station %i] : Station closing\n", ThisStation);
}