Reading input from stdin using scanf() in C

前端 未结 1 1789
野趣味
野趣味 2020-12-22 09:44

Assuming that the inputs are:

6 4
0 1 2 2 1 0
1 0 0 0 0 1
1 0 0 0 0 1
0 1 1 1 1 0

6 and 4 are width and height respectively. What I used i

1条回答
  •  星月不相逢
    2020-12-22 10:39

    You can use gets, strtok and atoi to get it done.

    Following is complete working code. See here working:

    #include 
    #include 
    
    int main(void) {
        int w, h, i, j;
        char buffer[100];
        scanf("%d %d", &w, &h);
        int num[w][h];
        gets(buffer);
        for(i=0; i

    0 讨论(0)
提交回复
热议问题