Thread: Scan and print an array in separate functions? (problem with code)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2019
    Posts
    2

    Question Scan and print an array in separate functions? (problem with code)

    I'm learning about arrays and functions for a school assignment, so i wrote a test program to check if i understood the theory, but when i print the array the output is wrong.

    I just started learning and i honestly have no idea what i'm doing wrong.

    Code:
    #include <stdio.h>
    
    
    #define TAMF 2
    #define TAMC 3
    void scanArray(int array[][]);
    void printArray(int array[][]);
    
    
    int main()
    {
        int array[TAMF][TAMC];
        scanArray(array);
        printArray(array);
    }
    
    
    void scanArray(int array[][])
    {
        int i,j;
        for(i=0; i<TAMF;i++) {
            for(j=0;j<TAMC;j++){
                printf("Input array[%d][%d]:\n>", i, j);
                scanf("%d", &array[i][j]);
            }
        }
    }
    
    
    void printArray(int array[][])
    {
        printf("\n------array------\n");
        int i,j;
        for(i=0; i<TAMF;i++){
            for(j=0;j<TAMC;j++){
                printf("%d\t",array[i][j]);
            }
            printf("\n");
        }
    }
    For example, if i input:
    1 2 3 4 5 6

    It outputs:
    4 5 6
    4 5 6
    Last edited by maya_s; 08-31-2019 at 09:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do i scan and print an integer?
    By ziggy786 in forum C Programming
    Replies: 3
    Last Post: 01-28-2013, 06:05 PM
  2. Functions in a separate file
    By Fox101 in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 02:53 PM
  3. scan an image and print it
    By hephaest in forum C Programming
    Replies: 18
    Last Post: 09-08-2006, 04:34 PM
  4. Using strtok on separate functions
    By Thumper333 in forum C Programming
    Replies: 2
    Last Post: 10-24-2004, 02:19 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread