Thread: C Program help

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    4

    C Program help

    this is what i need my program to do. I am having problems at multiple stages so i will put what i have even tho it might be fragmented. please help!

    2. it should prompt the user for the input file name of the file containing the data to sort.
    3. If the program can't open the file or if no file name is entered (^d or ^z is entered for EOF), it should print an error message and exit.
    4. The file will contain numbers that could be positive or negative integers or floating point numbers two numbers to a line.
    5. The program should only handle the first 90 numbers in the file.
    6. The program should read the numbers from the file into an array and then sort in ascending order (low to high) them.
    7. If the program encounters a non-numeric value in the file, it should print an error message indicating the line number of the line containing the error and discard that input line in the file and go to the next line.
    8. The program should print the sorted list of numbers, four numbers to a line in columns fifteen characters wide with four digits to the right of the decimal point.
    9. After printing the sorted list, it should print:
    o There were <number> numbers found in file <file name>.
    o The largest number found was: <number>
    o The smallest number found was: <number>
    o The average of the values is: <number>
    10. If there are no numbers in the file, the program should only print the following line
    o There were 0 numbers found in file <file name>.
    11. Include comments in your code (see project two for the required comment block formats) to explain what the code does.
    12. See the examples below for spacing and formatting.
    13. Your program should be well structured. The work should be done in functions, not in main. Include at least four functions that you will define.
    14. The program can not use global variables except for a debug variable.





    Code:
    #include <stdio.h>
    void greeting(void);
    void sortArray (float *nums[], int *last);
    int main()
    {
    float nums;
    int last;
    greeting();
    sortArray(&float nums[90], &int last);
    return 0;
    }
    
    void greeting ()
    {
    printf("Hello World! My name is Daniel Greene");
    return;
    }
    
    void sortArray(float *nums[], int *last)
    {
        int smallest;
        int temp;
    
        for (int current = 0; current < last; current++)
        {
            smallest = current;
    
            for (int walk = current + 1; walk <= last; walk++){
                if (nums[walk] < nums[smallest]){
                     smallest = walk;
                     temp = (float)nums[current];
                     nums[current] = nums[smallest];
                     nums[smallest] = (float)temp;
                }
    }
    
    return;
        }


    then I have some code here too that i dont know whats going on.

    Code:
    #include <stdio.h>
    
    // Function Declarations
    void greeting();
    int openFile(FILE* FP);
    MAX_SIZE [90];
    
    int main (void)
    /* Local Declarations */
    
    {
    float nums[90];
    FILE*FP;
    
    greeting();
    openFile(&FP);
    /*Statements*/
    
    
    return 0;
    } /* end of Main */
    
    
    /* Function Name: greeting
    
     * Input Parameters: none
    
     * Description: Function prints out class, project and name.
    
     * Return Value: returns nothing.
    */
    void greeting ()
    {
    printf("\n\nCOP 2220-50184 Project 3: Daniel Greene\n\n") ;
    return;
    }
    
    
    int openFile(FILE** FP)
    {
    int fName
    
    printf("\n\nEnter File Name\n\n") ;
    scanf("%s, fName");
    fopen(fName, "r");
    if(!fName)
        {
         printf("File name not valid.\n");
        }
    
    
    
    
    return FP;
    }
    Last edited by dgilroy1210; 06-29-2011 at 11:13 AM. Reason: forgot requirements

  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
    How much are you willing to pay?
    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
    Jun 2011
    Posts
    4
    40...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What am I going to do with 40 ellipses? Pause in thought a lot I guess. Why did you post your "do it for me" question on the C++ board when you want C?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4
    This is a C programming thread

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    My original post was going to be about how you aren't getting your program done because you don't know how to read. Your latest post proves that point.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Hmm... this sort function seems strangly similar to this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help converting array program to link list program
    By hsmith1976 in forum C++ Programming
    Replies: 0
    Last Post: 02-14-2010, 09:50 PM
  2. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM

Tags for this Thread