1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

Tags:
  1. Oct 27, 2014 #1

    sheldonrocks97

    User Avatar
    Gold Member

    1. The problem statement, all variables and given/known data
    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

    2. Relevant equations


    3. 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!
     
  2. jcsd
  3. Oct 27, 2014 #2

    jedishrfu

    Staff: Mentor

    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 (Text):

    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.
     
  4. Oct 27, 2014 #3

    sheldonrocks97

    User Avatar
    Gold Member

    Thank you. My friend and I got the help we needed.
     
  5. Oct 27, 2014 #4

    jedishrfu

    Staff: Mentor

    That's great if you run into specific questions or problems with your code, post it and we can provide some help.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Write a C program to read values for times from the input file?
Loading...