A lil bit of help :)

Discussion in 'C' started by hazi_, Jan 19, 2012.

  1. hazi_

    hazi_ New Member

    Joined:
    Jan 19, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys I really need some help with one C program. I don't really know where to start from so I'll be happy to all of your advices :) I'm a beginner at C and I know all the stuff but my teacher decided to give us one task which is "pretty easy" according to him but all we've studied so far is if-else and those kind of stuff. So this is it:


    In the text file C:\data\myfile.txt there are some integer numbers separated with one or more spaces. Write:
    1) function: for copying the file int myCpy( FILE *); in a file with name given from the user (which is opened in the function) , and replacing all the spaces with tabs.
    2) function void midl( FILE *); for displaying the average of the numbers higher than 10 and lesser than 20.
    3) function main() , which opens the file, calls the two funtions and closes the file.


    Thanks to all the repies in advance :))
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    With homework, you'd be better off posting what you've tried. I'll try a give a few ideas based on what you've posted though.

    replace spaces with tabs
    Code:
       while(string index position is valid) {
          if(current character at index position is a space, make it a tab)
          increment position
       }
    
    find average of values > 10 and < 20
    Code:
       keep a count of integers found to be > 10 and < 20
       sum the integers in the above range
     
       while(file being read is valid) {
          if(variable stored > 10 && variable stored < 20) {
             increment counted integers
             sum += variable stored
          }
       }
    
       output sum / count
    
    open user defined file
    Code:
       create a char array to hold file name
       ask user for name
       try to open file by that name
       
       if(file name is good) {
          function 1
          function 2
          close file handle
       } else {
          show error message
       }
    
    Give it whirl.

    HTH
     
  3. hazi_

    hazi_ New Member

    Joined:
    Jan 19, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much :) I'll try to make the whole program but if I have any problems I'll get back to you :) This is very helpful thanks :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice