Why wont this compile?

This is a discussion on Why wont this compile? within the C Programming forums, part of the General Programming Boards category; I added the section at the bottom from "intmain" to "printf", and it still will not compile. Any ideas?...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    4

    Why wont this compile?

    I added the section at the bottom from "intmain" to "printf", and it still will not compile. Any ideas?
    Attached Files Attached Files

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can't just stick "int main" inside another function.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,530
    Your assignment is to finish the following functions
    printBoxList(float boxes[MAX_BOXES][6], int n);
    writeBoxesToFile(char fileName[],float boxes[MAX_BOXES][6], int n);
    And you have
    Code:
    void writeBoxesToFile(char fileName[], float boxes[MAX_BOXES][6], int n)
    {
         FILE *fp;
         
         fp = fopen(fileName, "w");
         if (fp == NULL){
              printf("unable to open file for writing\n");
              return;   
         }
         fprintf(fp, "%d\n", n);
         
         fclose(fp);
    }
    
    /*
    
                finish this function to print a table 
                of the box coordinates
                
                Make sure to label the columns
    */
    void printBoxList(float boxes[MAX_BOXES][6], int n)
    
         int main()
       {
         int row
         int column 
         
         for (row= -1; row<n; ++row)
          for(column=-1; column<6; ++column)
          }
     {
         printf("printBoxList,[row],[column]\n");
    Do you understand what you're supposed to be doing here?
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    I guess not, I thought I was to finish the bottom part of the source code, which I thought I did, I haven't figured out how to label yet but It should still run the way I have it .

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Dieselfreak View Post
    I guess not, I thought I was to finish the bottom part of the source code, which I thought I did, I haven't figured out how to label yet but It should still run the way I have it .
    No it won't... amongst other things C does not support nested functions... that is you cannot define a function inside a function.

    On top of that the code you obviously added by cut and past appears to have nothing to do with the remainder of the program.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,530
    There is no main() in that source file (did you read the instructions?)

    All you're supposed to do is
    Code:
    void writeBoxesToFile(char fileName[], float boxes[MAX_BOXES][6], int n)
    {
         FILE *fp;
         
         fp = fopen(fileName, "w");
         if (fp == NULL){
              printf("unable to open file for writing\n");
              return;   
         }
         fprintf(fp, "%d\n", n);
         /* YOUR CODE HERE */
         
         fclose(fp);
    }
    
    /*
    
                finish this function to print a table 
                of the box coordinates
                
                Make sure to label the columns
    */
    void printBoxList(float boxes[MAX_BOXES][6], int n)
    {
        /* YOUR CODE HERE */
    }
    You can "label the columns" later.
    Try just getting something to print out the basic information.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 01:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 12:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 07:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 08:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 01:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21