Write a C program to read values for times from the input file?

AI Thread Summary
The discussion revolves around a homework assignment requiring the creation of a C program that reads time values from an input file named times.txt, computes the sine of each time multiplied by 5π, and outputs the results to output.csv in a comma-separated format. Participants emphasize the importance of completing the assignment independently and suggest referring to textbooks for guidance on file handling and mathematical computations. Pseudocode is provided to assist in structuring the program, highlighting the steps of opening the file, reading values, performing calculations, and printing results. The conversation encourages students to seek help with specific coding issues rather than asking for complete solutions. Overall, the focus is on learning and understanding the programming concepts involved in the task.
sheldonrocks97
Gold Member
Messages
66
Reaction score
2

Homework Statement


Write a C program to read values for times from the input file times.txt; compute sin(5*pi*t) for each time t given in times.txt; output comma separated values of t, sin(5*pi*t) into an output file named output.csv; and compile the program using a makefile. Hand in a copy of your program, output file, and makefile.

LIST OF TIMES:

0
0.0121
0.0241
0.0362
0.0483
0.0603
0.0724
0.0845
0.0965
0.1086
0.1207
0.1327
0.1448
0.1569
0.1689
0.1810
0.1931
0.2051
0.2172
0.2293
0.2413
0.2534
0.2655
0.2775
0.2896
0.3017
0.3137
0.3258
0.3379
0.3499
0.3620
0.3741
0.3861
0.3982
0.4103
0.4223
0.4344
0.4465
0.4585
0.4706
0.4827
0.4947
0.5068
0.5189
0.5309
0.5430
0.5551
0.5671
0.5792
0.5913

Homework Equations

The Attempt at a Solution


#include<stdio.h>

#include<math.h>

void main (void)

{

FILE *times.txt, *output.csv; //input/output files//

int t; //time variable//

int x = sin(5*M_PI*t);Please help my friend and I are very very desperate!
 
Physics news on Phys.org
I'm sorry to say that while many of us could easily write this program, we can't in good conscience do it. This is your homework assignment you and your friend need to mount a valiant defense, read your book and just get down and do it. It should take no more than an hour or so to write.

I can show you some pseudo code to follow that may help you get started. Also you can easily find program recipes that read files, convert strings to numbers, compute values and print them out which are the basic things your program needs to do.

Some pseudo code:

Code:
Open file
For each line in the file
{
        Read one number
        Compute sin()
        Print t, comma, sin()
}
Close file

So follow each line and look up in your book for things that match what the line does.
 
Thank you. My friend and I got the help we needed.
 
  • Like
Likes jedishrfu
That's great if you run into specific questions or problems with your code, post it and we can provide some help.
 
Back
Top