I am fairly new to C and I am making a C program that should works like this: it has one thread which reads a file with a double on each line of the file, and:
- it should be able to read files of any size.
- after reading the double it should perform this
n=atan(tan(n)
calculation.
I have the following example:
void* ReadFile(void *file){
char *str;
str = (char*)file;
printf("Opening File\n");
FILE* f = fopen(str,"w");
fclose(f);
printf("Closing File\n");
}
void main(){
pthread_t t1;
pthread_create(&t1,NULL,open_file,"data.txt");
pthread_join(t1,NULL);
}
where should I perform the operation? should it be in main or in ReadFile is also fine. The other problem I have is that how can you make sure it reads a file of any size? Should I use sizeof(str)
in order to get the length/size of the file and then make a for loop that reads a line at each iteration and performs the calculation? Is this a good way of doing this in C?