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 )
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
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