Thread: need help ...

  1. #1
    Registered User
    Join Date
    Oct 2018

    need help ...

    hello for the input 5 5 my code is supposed to print this:

    * *
    * *
    * *

    but it prints:
    this is my code:
    int main(){
    int x,y;
    int i,j,k,l;
    char wall [x] [y];
    scanf("%d %d",&x,&y);
    for( i=0;i<x;i++){
    for( j=0;j<y;j++){
    wall [i][j]='*';
    else if(i==x-1)
    wall [i] [j]='*';
    else if(j==0)
    wall [i] [j]=='*';
    else if(j==y-1)
    wall [i] [j]='*';
    wall [i][j]=' ' ;
    for( k = 0 ; k < x; k++ ) {
    for( l= 0 ; l < y ; l++ ) {
    printf("%c", wall[k][l]);
    return 0;}

    can you tell me what kind of mistake i make here thank you ...
    Last edited by kyper78; 12-08-2018 at 12:22 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Your indentation is non-existant.
    Indentation style - Wikipedia

    Your variable names are lousy.
    Everything apart from i and j (your loop control variables) should have a meaningful name.
    Like x is numRows, y is numCols.

    > char wall [x] [y];
    > scanf("%d %d",&x,&y);
    Arrays don't magically resize just by assigning variables.
    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.

Popular pages Recent additions subscribe to a feed

Tags for this Thread