Thread: Modify this code using a functions

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    1

    Modify this code using a functions

    My original code is here, I need to pass the value for row,Right and step with functions. I would like to do all the logic in the function and only print the array in int main.

    Code:
    #include <stdio.h>
    
    
    
    int main ()
     {
    
    
    int i,k,x;
    int c, f;
    char z;
         char a[4][4] = { {'*','*','*','*'}, {'*','*','*','*'}, {'*','*','*','*'}, {'*','*','*','*'}};
    
    
            printf("From the right\n");
            z=getchar();
    
    
    
    
            printf("Row\n");
            scanf("%d",&c);
    
    
            if(z=='R')
            {
                printf("Steps");
                scanf("%d",&f);
                a[c][f]='G';
    
    
                for ( i = 0; i < 4; i++ ) {
    
    
          for ( k = 0; k < 4; k++ ) {
             printf("%c ", a[i][k] );
          }
          printf("\n");
       }
            }
            return 0;
       }

    This is the modified code lol I know it looks terrible. I would appreciate any suggestions. Thanks
    Code:
    #include <stdio.h>void print(char);
    
    
    int main ()
     {
    
    
    
    
         char a[4][4] = { {'*','*','*','*'}, {'*','*','*','*'}, {'*','*','*','*'}, {'*','*','*','*'}};
    
    
            printf("From the right\n");
            z=getchar();
    
    
              //  modified array goes here []
    
    
            void print(char z){
    int i,k;
    int c, f;
    
    
            if(z=='R')
            {
                printf("Row\n");
                    scanf("%d",&c);
    
    
                printf("Steps");
                    scanf("%d",&f);
                        a[c][f]='O';
    
    
                for ( i = 0; i < 4; i++ ) {
    
    
          for ( k = 0; k < 4; k++ ) {
             printf("%c ", a[i][k] );
          }
          printf("\n");
       }
            }
            return ;
       }
    Last edited by Sammyft; 10-16-2016 at 05:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Should I modify the code
    By Satya in forum C Programming
    Replies: 4
    Last Post: 10-12-2015, 01:33 AM
  2. need help in modify my code
    By mritay in forum C Programming
    Replies: 1
    Last Post: 12-18-2012, 07:59 AM
  3. help modify code 6 x 24 to 10 x 24 led matrix
    By visualfx in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2012, 02:04 PM
  4. can someone help me modify the code of Metapad?
    By Rigel in forum C Programming
    Replies: 2
    Last Post: 10-17-2009, 09:17 AM
  5. modify my code
    By BEN10 in forum C Programming
    Replies: 3
    Last Post: 03-28-2009, 01:48 AM

Tags for this Thread