Thread: Basic C Help!

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    Basic C Help!

    Hey guys, just wondering if anyone could help me out - it would be greatly appreciated!

    Basically, I need to write a C program which will take data from a text file and be able to manipulate it to give an answer.

    There are 3 text files, each containing 10 numbers. The user will choose the text file, and then the 10 values within that will be put into an array i assume? From there each value will be put into a small formula to give 10 new values. Then all 10 new values will be put into a final formula (simpson's rule for iteration) to give one final value.

    I am at a loss as to how to go about doing this!

    Any help or pointers would be greatly appreciated! Thank you

  2. #2
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Prompt the user to enter the file name.
    Open that file, read its contents into an array, close the file.
    Apply formula to each value and put in second array.
    Put 10 final values into simpsons rule to get final value and presumable display that value.

    Have you any experience of writing C programs at all?

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >> I am at a loss as to how to go about doing this!

    Well it's nice to know that you have some ideas. Lets go over what you said:

    >> There are 3 text files, each containing 10 numbers. The user will choose the
    >> text file, and then the 10 values within that will be put into an array i
    >> assume?

    That sounds like a good start. Let the user provide you with a filepath, and then open it using C's file I/O interface. Look in your book for information about how to handle files and how to get text from them. Or you could look at our parent site, www.cprogramming.com for File I/O tutorials.

    As you read the file, you will need to convert from text to a numerical type (so that doing math is easier). You can learn how to do that here, too. Read How to get a number from the user

    >> From there each value will be put into a small formula to give 10 new
    >> values. Then all 10 new values will be put into a final formula (simpson's
    >> rule for iteration) to give one final value.

    Well, try to understand the formulas first. I'm not really sure what Simpson's rule is, but the better you understand the formula the easier it should be to program a solution. After you understand that, a simple solution can be found by:

    Solve a sample problem using Simpson's rule.
    Examine the basic tools you have at your disposal in C (loops, arithmetic, basic math functions, etc.)
    Focus on expressing each step to the solution in C code.
    Test your algorithm: practice on a pretend file and see how well it works.

    HTH

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Basic httpd server
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 07-28-2002, 06:14 PM