CFanatic

Go Back   CFanatic > Programming > C Programming

Join CFanatic Forum Now

A lil bit of help :) topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 01-19-2012, 01:19 PM
Junior Member
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
hazi_ is on a distinguished road
| More
A lil bit of help :)

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 )
Reply With Quote
  #2  
Old 01-19-2012, 06:31 PM
hobbyist's Avatar
Member
 
Join Date: Jan 2012
Posts: 55
Thanks: 1
Thanked 20 Times in 16 Posts
hobbyist is on a distinguished road
| More
Re: A lil bit of help :)

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
Reply With Quote
The Following User Says Thank You to hobbyist For This Useful Post:
shabbir (01-19-2012)
  #3  
Old 01-20-2012, 03:42 AM
Junior Member
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
hazi_ is on a distinguished road
| More
Re: A lil bit of help :)

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:38 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board