Thread: turning data file full of 380 decimal numbers into array or string

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    3

    turning data file full of 380 decimal numbers into array or string

    hi, very new to C programming. i have opened a data file which has 380 decimal numbers ranging from .90 - 1. i need to first round these number to two decimal places then sort label them into categories (.90-.92 = 1 ,.93-.94 = 2, and so on.) i need to be able to save the data file so i can manipulate it, and this is where i am stuck!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So where are you stuck?
    - reading the file
    - rounding to 2dp
    - allocating to bins
    - writing the results.

    Post some code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2016
    Posts
    3
    Quote Originally Posted by Salem View Post
    So where are you stuck?
    - reading the file
    - rounding to 2dp
    - allocating to bins
    - writing the results.

    Post some code.
    i have rounded the data to 2 decimals, now i am trying to turn the data file into an array where i can the label them 1 - 5 and keep a frequency count.
    Last edited by gtrain; 09-25-2016 at 03:04 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about a series of if / else if tests for the ranges ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2016
    Posts
    3
    i have all the ranges sorted but i don't know how to open the data file and edit it so i can label each number 1-5
    Code:
    if (grade <.92 )
                              printf("\n data=%5.2f, score=%c", grade, '1');
                          else
                              if (grade <.94 )
                                  printf("\n data=%5.2f, score=%c", grade, '2');
                              else
                                  if (grade < .96)
                                      printf("\n data=%5.2f, score=%c", grade, '3');
                                  else
                                      if (grade <.98)
                                          printf("\n data=%5.2f, score=%c", grade, '4');
                                      else
                                          if (grade <1.01)
                                              printf("\n data=%5.2f, score=%c", grade, '5');
                }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well if you've mastered printf(), then you should be able to do the same with fprintf()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-02-2014, 09:41 AM
  2. Replies: 7
    Last Post: 06-23-2013, 06:30 AM
  3. Printing random decimal numbers in a text file
    By warrick in forum C Programming
    Replies: 3
    Last Post: 03-08-2010, 09:32 AM
  4. Replies: 2
    Last Post: 03-08-2009, 08:54 PM
  5. How do you assign Full names to a array string
    By Demipimp in forum C Programming
    Replies: 9
    Last Post: 12-05-2008, 12:56 PM

Tags for this Thread