Like Tree2Likes
  • 2 Post By stahta01

Program won't compile

This is a discussion on Program won't compile within the C Programming forums, part of the General Programming Boards category; Edit: My program will not compile, i'm not sure what the issue is. can anyone read it over for me ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    2

    Program won't compile

    Edit:
    My program will not compile, i'm not sure what the issue is. can anyone read it over for me

    Code:
    /*
    
    
    
    #define NRows 21	// Dimensions for grid
    #define NCols 51
    
    
    #include <stdio.h>
    #include <string.h>
    
    
    /**** FUNCTION PROTOTYPES ****/
    // Reset grid to original settings
    void resetGrid(char grid[][NCols]);
    
    
    // Add box to existing grid starting at (x, y) with specified width & height
    void addBox(char grid[][NCols], int x, int y, int width, int height);
    
    
    // Print current grid contents
    void printGrid(char grid[][NCols]);
    /***** END FUNCTION PROTOTYPES *****/
    
    
    void main() {
    	char myGrid[NRows][NCols];
     void main()
     {
     	int arr[nrow][ncols];
     	int rows,columns;
     	int rownum, colnumn, value,i=0,j=0;
     	char command[15];
     	char set[]="set";
     	char add[]="add";
     	char reset[]="reset";
     	char exit[]="exit";
     
     	while(1)
     	{
     		printf("Input coordinates: ");
     		scanf("%d %d",&rows,&columns);
     		if (((rows>20)|| (rows<0))||((columns>50)|| (columns<0)))
     			printf("Improper dimensions %i %i \n",rows,columns);
     		else
     			break;
     	while (1)
     	{
     		printf("Input command: ");
     		scanf("%s",&command);
     		if (strcmp(set,command)==0)
     		{
     			printf("Input row, column, and value: ");
     			scanf("%d %d %d",&rownum,&colnumn,value);
     			readval(&rownum,&colnumn,&value,rows,columns);
     			printf("%d %d %d",rownum,colnumn,value);
     			arr[rownum][colnumn]=value;
     			printgrid(arr,rows,columns);
     			
     		}
     		if (strcmp(add,command)==0)
     		{
     			printf("Input row, column, and value: ");
     			scanf("%d %d %d",&rownum,&colnumn,value);
     			readval(&rownum,&colnumn,&value,rows,columns);
     			arr[rownum][colnumn]+=value;
     			printgrid(arr,rows,columns);
     			
     		}
     		if (strcmp(add,command)==0)
     		{
     			printf("Input row, column, and value: ");
     			scanf("%d %d %d",&rownum,&colnumn,value);
     			readval(&rownum,&colnumn,&value,rows,columns);
     			arr[rownum][colnumn]+=value;
     			printgrid(arr,rows,columns);
     			
     		}
     
     		
     		if(strcmp(reset,command)==0)
     		{
     			for( i=0;i<rows;i++)
     			{
     				for( j=0;j<columns;j++)
     				{
     					arr[i][j]=0;
     				}
     			}
     			printgrid(arr,rows,columns);
     			continue;
     		}
     		if(strcmp(exit,command)==0)
     		{
     			break;
     		}
     		else
     			printf("Value is invalid please try again");
     	}
     	}
     
     }
     void readval(int *numrows, int *numcolm,int *val,int rowmax,int colmax)
     {
     	char store;
     	while(1)
     	{
     		if((*numrows>=rowmax)|| (&numrows<0))
     			printf("Invalid row number");
     		if((*numcolm>=colmax)|| (&numcols<0))
     			printf("Invalid row number");
     		else
     			break;
     	printf("Input number of rows, columns, and value: ");
     	scanf("%i %i %i",numrows,numcols,val);
     	}
     }
    
    
     void printgrid(int max[nrow][ncols],int r, int c)
     {
     	int i,j;
     	for(i=0;i<r;i++)
     	{
     		for(j=0;j<c;j++)
     		{
     			printf("%7i \n",max[i][j]);
     		}
     	}
     }
    The objective of the assignment can be found here
    http://mgeiger.eng.uml.edu/16216/pro...og7_raster.pdf
    Last edited by bmryner; 12-10-2012 at 03:19 PM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,241
    It is not against the forum policies to post homework code here. Here is the full link on the homework policy: Announcements - General Programming Boards

    Just be sure you aren't breaking any class rules by posting your code on a public forum.

    There is also the option of re-writing your program more generically, in a way that will illustrate the problem you are having without actually being your assignment.

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    It is against the rules to ask us to do your entire assignment. It is also against the rules to be a twat. That's about all you need to know. If you can't get something to compile that means you have a legitimate question. You've at least tried to do it yourself.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,516
    If you get Compiler errors, you should post the errors by cutting and pasting them between code tags.
    If no errors, it will help if you state your OS name, Compiler/IDE name.

    Tim S.
    AndiPersti and bmryner like this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Your file starts with a multi-line comment, so the #defines and #includes are omitted

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    2,241
    ... and you have "main()" started twice:

    Code:
    void main() {
        char myGrid[NRows][NCols];
     void main()
     {
        int arr[nrow][ncols];
        int rows,columns;
        int rownum, colnumn, value,i=0,j=0;
        char command[15];
        char set[]="set";
        char add[]="add";
        char reset[]="reset";
        char exit[]="exit";
    And you should declare "main()" as returning an "int" ("int main(void)")
    FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[]) - Cprogramming.com

  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by bmryner View Post
    My program will not compile,
    And why don't you post the compiler errors/warnings as Tim has told you?

    Bye, Andreas

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    2,516
    C is case sensitive as in "NRows" is not the same as "nrows".

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  9. #9
    Registered User
    Join Date
    Dec 2012
    Posts
    3
    So why are you in an course that requires an electrical or computer engineering major if you are not willing to read through the program and attempt to fix it? You may want to look at changing majors to something else. Also this thread is being emailed to your professor, this is called academic dishonesty. aka cheating.

  10. #10
    Registered User
    Join Date
    Dec 2012
    Posts
    2
    how is it cheating if I've put in the effort to write the program. is this not similar to a tutoring process?
    Last edited by bmryner; 12-11-2012 at 07:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC compile c program
    By aweida in forum C Programming
    Replies: 6
    Last Post: 10-01-2010, 11:27 AM
  2. I have a program to compile,need help.
    By wxjeacen in forum C Programming
    Replies: 12
    Last Post: 10-20-2008, 02:24 AM
  3. new to C--can't get program to compile
    By samerune in forum C Programming
    Replies: 12
    Last Post: 04-02-2007, 09:44 AM
  4. Compile the program?
    By marrk in forum C Programming
    Replies: 2
    Last Post: 09-17-2006, 10:02 AM
  5. program won't compile?
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2006, 07:09 PM

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