Is my code right so far??

This is a discussion on Is my code right so far?? within the C Programming forums, part of the General Programming Boards category; Here is what my project is http://www.cs.iupui.edu/~cs230/w_proj4.html Is the code I have so far correct? this part of the code ...

  1. #1
    unregistered
    Guest

    Angry Is my code right so far??

    Here is what my project is http://www.cs.iupui.edu/~cs230/w_proj4.html
    Is the code I have so far correct? this part of the code gets the coordinates from the user. What do I need to change and etc.? Any help is greatly appreciated. Ignore the parts that I haven't got to yet or offer help in those areas too. Thank you


    #include <stdio.h>
    #define SIZER 10
    #define SIZEC 15
    int initconfig(int [][], int, int);
    int generate ();
    int occ();
    int printgrid();
    #include <stdio.h>
    #define SIZER 10
    #define SIZEC 15
    int initconfig(int [][], int, int);
    int generate ();
    int occ();
    int printgrid();

    int main()
    {

    int a[SIZER][SIZEC];

    initconfig( a, SIZER, SIZEC );
    }
    int initconfig( int a[SIZER][SIZEC],int i, int j)
    { while( i!= -1)
    { for(i=0; i<=1; i++)
    for(j=0; j<=1; j++)
    scanf("%d", &a[i][j]);
    }
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    #include <stdio.h>
    #define SIZER 10
    #define SIZEC 15
    int initconfig(int [][], int, int);
    int generate ();
    int occ();
    int printgrid();
    #include <stdio.h>
    #define SIZER 10
    #define SIZEC 15
    int initconfig(int [][], int, int);
    int generate ();
    int occ();
    int printgrid();
    Um... you need to not have all that in there twice. That'd be a start.

    Code:
    int initconfig( int a[SIZER][SIZEC],int i, int j) 
    {
       while( i!= -1) 
       {
           for(i=0; i<=1; i++) 
             for(j=0; j<=1; j++) 
                scanf("%d", &a[i][j]); 
      } 
    }
    No. This is wrong. Your loop will never end.

    What exactly are you trying to do? Get user input and when they enter -1 have it stop?

    If so, use a do-while loop, or just use a conditional return statement:
    Code:
    while(1)
    {
       for()for() //use your for loops similar to above, except have them
       //bounry set by the passed arguments. I'm not doing all your
       //homework for you.
          scanf("%d", a[x][y] )
          if( a[x][y] == -1 ) return;
    }
    }
    }

    For future reference, give a quick summary of what your code is supposed to do. I refuse to wander off to some random link describing your homework or code project. If you (anyone) want some help, post a bit of code, and explain what you are expecting to happen and what error you're getting.

    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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