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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 2K views
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   Reactions: jedishrfu