vendredi 29 mai 2015

How to scanf to just one dimension of a multidimensional array in C?

Suppose I have some C code like this, which declares a small multidimensional array:

#include <stdio.h>
#include <conio.h>

int main(void)
{
    int mat[5][2] = {
        {0, 0},
        {0, 0},
        {0, 0},
        {0, 0},
        {0, 0}
    }

    do scanf("%i", &mat[][]);
    while (getchar() != '\n');  

    return 0;
}

and I want to change do scanf("%i", &mat[][]);, and possibly the line below it, to something which will allow me to read user-supplied integers into only the 2nd column of this 5-by-2 multidimensional array.

Iam trying to find the simplest possible solution, without concern for software security and hopefully without unnecessarily calling libaries.

Aucun commentaire:

Enregistrer un commentaire