C/How to save asin Values in a file ?
Expert: Prince M. Premnath - 3/24/2008
QuestionHi,
I have one question related to filehandling in c.
Q:How i can store the different values of a sine wave equation
y=a sin(wt)in a file in the form of matrix.
i would be greatful if u could help me out for finding a solution.
Thanks and Regards,
Smita
AnswerHai Dear Samita !
Perhaps its simple to store the values of a sine wave equation, just follow the simple steps .
1. Create simple structure with two members say x , and asin of type double.
eg
struct sinvals
{
double x;
double val;
}structvar;
2. Create a structure variable .
3. Read the value of x , and calculate the corresponding asin value of x using the built in function and store the result in the member val.
4. Now write the contents of the structure variable onto the output file
Using this statement !
fwrite(&structvar , sizeof(structvar) , 1 , fileptr);
The code given above is self explanatory , say structvar is structure variable , fileptr refers the pointer to the output file ! the 3rd argument 1 refers number of records to be written on file !
For more queries and doubts feel to post a follow up !
Thanks and Regards !
Prince M. Premnath