Help with code from "O'Reily's Practical C Prgramming, 3rd Edition"

From: Scott (scottgin_at_yahoo.com)
Date: 03/29/04


Date: 28 Mar 2004 14:28:55 -0800

Hi Folks,
 I hope someone can help me spot the mistake here. The code here is
from the O'Reily book "Practical C Programming", 3rd edition. I am
running Libranet Linux with kernel 2.4.19. I am using gcc version
2.95.4 20011002 (Debian prerelease). I have went over the code a
number of times and cannot see any typos. I'm stuck! When I try to
compile, I get the folling error.

Thanks for any help anyone can give in advance!!

Scott

The error when I try to compile is:

========
$ gcc -g -Wall -op_array p_array.c
p_array.c: In function `main':
p_array.c:31: warning: left-hand operand of comma expression has no
effect
p_array.c:31: warning: int format, pointer arg (arg 2)
p_array.c:32: warning: left-hand operand of comma expression has no
effect
p_array.c:32: warning: int format, pointer arg (arg 2)
p_array.c:36: warning: left-hand operand of comma expression has no
effect
p_array.c:36: warning: int format, pointer arg (arg 2)
p_array.c:37: warning: left-hand operand of comma expression has no
effect
p_array.c:37: warning: int format, pointer arg (arg 2)
p_array.c:41: warning: left-hand operand of comma expression has no
effect
p_array.c:41: warning: int format, pointer arg (arg 2)
p_array.c:42: warning: left-hand operand of comma expression has no
effect
p_array.c:42: warning: int format, pointer arg (arg 2)
p_array.c:21: warning: unused variable `y'
p_array.c:21: warning: unused variable `x'
========

The code is:

========
#include <stdio.h>

int array[3][2]; /* Array of numbers */

int main()
{
        int x,y; /* Loop indicies */

        array[0][0] = 0 * 10 + 0;
        array[0][1] = 0 * 10 + 1;
        array[1][0] = 1 * 10 + 0;
        array[1][1] = 1 * 10 + 1;
        array[2][0] = 2 * 10 + 0;
        array[2][1] = 2 * 10 + 1;
        
        printf("array[%d] ", 0);
        printf("%d ", array[0,0]);
        printf("%d ", array[0,1]);
        printf("\n");

        printf("array[%d] ", 1);
        printf("%d ", array[1,0]);
        printf("%d ", array[1,1]);
        printf("\n");

        printf("array[%d] ", 2);
        printf("%d ", array[2,0]);
        printf("%d ", array[2,1]);
        printf("\n");

        return (0);
}
===========


Quantcast