次のプログラムの警告とエラーについて教えていただきたいです。
# include <stdio.h>
# define MAX 25
int main(){
/* Q1 */{
int v;
printf("***Q1***\n");
printf("&v = %08x\n",&v);
}
/* Q2,Q3 */{
int m[5];
printf("\n***Q2***\n");
printf("&m[5] = %08x\n",&m[5]);
printf("m+5 = %08x\n",m+5);
printf("***Q3***\n");
printf("&m[0] = %08x\n",&m[0]);
printf("m = %08x\n",m);
}
/* Q4 */{
int d[1][1];
printf("\n***Q4***\n");
printf("&d[0][0] = %08x\n",&d[0][0]);
printf("d[0] = %08x\n",d[0]);
printf("*d = %08x\n",*d);
}
/* Q5 */{
int a=2,b=3,c=5, *p, *q;
p = &b;
q = &c;
a = *p + *q;
printf("\n***Q5***\n");
printf("変数aの値 = %d\n",a);
}
/* Q6 */{
int a=2, *p;
p = &a;
*p = 5;
printf("\n***Q6***\n");
printf("変数aの値 = %d\n",a);
}
/* Q7 */{
int a=200,b=300,*p,*p1,**q;
printf("\n***Q7***\n");
printf("アドレス&aの値 => ",&a);
printf("a=%8d\n", a);
printf("アドレス&b ==> ",&b);
printf("&b=%08x :アドレス200の代り\n", &b);
printf("アドレス&bの値 => ",&b);
printf(" b=%8d\n", b);
p = &a;
q1 = &b;
q = &q1;
printf("*p=%d\n", *p);
printf("*q=%08x :アドレス200の代りと同じ! \n", *q);
printf("**q=%d\n", **q);
puts("omake");
printf(" q=%08x :アドレス100と考える\n", q);
}
/* Q8 */{
int m[]={1,2,3,4,5}, k;
printf("\n***Q8***\n");
for(k=0; k<5; k++){
printf("k = %d\n",m[k]);
printf("*(m+k) = %d\n\n",*(m+k));
}
}
/* Q9 */{
int *p, q;
p = &q;
p = &q;
printf("\n***Q9***\n");
printf("p = %08x\n",p);
printf("p+1 = %08x\n",p+1);
printf("p+2 = %08x\n",p+2);
}
/* Q10 */{
int m[]={1,2,3,4,5}, *p;
printf("\n***Q10***\n");
printf("m[0] = %d\n",m[0]);
printf("*m = %d\n",*m);
printf("b.\n");
p = m;
printf("*p = %d\n",*p);
printf("p[0] = %d\n",p[0]);
}
/* Q11 */{
static int m[5] = {10,20,40,50,30};
printf("\n***Q11***\n");
printf("*m = %d\n",*m);
printf("*(m+3) = %d\n",*(m+3));
printf("*m+3 = %d\n",*m+3);
printf("*m+*(m+3) = %d\n",*m+*(m+3));
}
/* Q12 */{
static int d[][3] = {{1,2,3},{5,6,7},{4,6,8},{9,7,5}};
printf("\n***Q12***\n");
printf("*d[2] = %d\n",*d[2]);
printf("*(d[2]+2) = %d\n",*(d[2]+2));
printf("*d[2]+2 = %d\n",*d[2]+2);
printf("**d = %d\n",**d);
printf("*(d+3) = %d\n",*(d+3));
printf("**d+6 = %d\n",**d+6);
printf("*(d[1]+2) = %d\n",(d[1]+2));
printf("**(d+2) = %d\n",**(d+2));
}
/* Q13 */{
char *str = "abcdefg" *p;
p = str+3;
printf("\n***Q13***\n");
printf("p = %s\n",p);
}
/* Q14 */{
char *p;
p = "abc";
printf("\n***Q14***\n");
printf("&(*p) = %8s(アドレス100の代り)\n",&(*p));
printf("p = %s\n",p);
printf("*p = %c\n",*p);
printf("*(p+2) = %c\n",*(p+2));
}
/* Q15 */{
static char m[] = "abcd";
char *p, *q;
p = &m[0];
q = m;
printf("\n***Q15***\n");
printf("*m = %c\n",*m);
printf("*p = %c\n",*p);
printf("*q = %c\n",*q);
}
/* Q16 */{
static char m[] = "abcd";
char *p;
p = &m[2];
printf("\n***Q16***\n");
printf("*p = %c\n",*p);
printf("*(m+2) = %c\n",*(m+2));
printf("*m+2 = %c\n",*m+2);
}
/* Q17 */{
char p[] = "abcd";
*(p + 1) = 'x';
printf("\n***Q17***\n");
printf("p = %s\n",p);
}
/* Q18 */{
int x;
char *p;
p = "abcd";
if(p == "abcd") x= 0;
else x = 1;
printf("\n***Q18***\n");
printf("x = %d\n",x);
}
/* Q19 */{
int k;
char m[MAX];
for(k=0; m[k]; k++) m[k] += 1;
printf("\n***Q19***\n");
printf("解答の明記\n int k;\n char m[MAX];\nfor(k=0; m[k]; k++) m[k] += 1;\n");
}
/* Q20 */{
static char *q[] = {"abcd", "12345", "ABCDEFG", "987"};
printf("\n***Q20***\n");
printf("*q[2] = %c\n",*q[2]);
printf("q[3][2] = %c\n",q[3][2]);
printf("*(q[2]+2) = %c\n",*(q[2]+2));
printf("*(*(q+3)+2) = %c\n",*(*(q+3)+2));
printf("**(q+1) = %c\n",**(q+1));
}
return(0);
}
このプログラムの警告とエラーが多すぎてどうしたらよいかわかりません。
repo.2.c:9:26: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("&v = %08x\n",&v);
~~~~ ^~
repo.2.c:14:29: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("&m[5] = %08x\n",&m[5]);
~~~~ ^~~~~
repo.2.c:15:29: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("m+5 = %08x\n",m+5);
~~~~ ^~~
repo.2.c:17:29: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("&m[0] = %08x\n",&m[0]);
~~~~ ^~~~~
repo.2.c:18:29: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("m = %08x\n",m);
~~~~ ^
repo.2.c:23:34: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("&d[0][0] = %08x\n",&d[0][0]);
~~~~ ^~~~~~~~
repo.2.c:24:34: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("d[0] = %08x\n",d[0]);
~~~~ ^~~~
repo.2.c:25:34: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("*d = %08x\n",*d);
~~~~ ^~
repo.2.c:47:42: warning: data argument not used by format string
[-Wformat-extra-args]
printf("アドレス&aの値 => ",&a);
~~~~~~~~~~~~~~~~~~~~~ ^
repo.2.c:49:36: warning: data argument not used by format string
[-Wformat-extra-args]
printf("アドレス&b ==> ",&b);
~~~~~~~~~~~~~~~~~ ^
repo.2.c:50:54: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("&b=%08x :アドレス200の代り\n", &b);
~~~~ ^~
repo.2.c:51:42: warning: data argument not used by format string
[-Wformat-extra-args]
printf("アドレス&bの値 => ",&b);
~~~~~~~~~~~~~~~~~~~~~ ^
repo.2.c:55:1: error: use of undeclared identifier 'q1'
q1 = &b;
^
repo.2.c:56:6: error: use of undeclared identifier 'q1'
q = &q1;
^
repo.2.c:58:59: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("*q=%08x :アドレス200の代りと同じ! \n", *q);
~~~~ ^~
repo.2.c:61:51: warning: format specifies type 'unsigned int' but the argument
has type 'int **' [-Wformat]
printf(" q=%08x :アドレス100と考える\n", q);
~~~~ ^
repo.2.c:76:22: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("p = %08x\n",p);
~~~~ ^
repo.2.c:77:23: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("p+1 = %08x\n",p+1);
~~~~ ^~~
repo.2.c:78:23: warning: format specifies type 'unsigned int' but the argument
has type 'int *' [-Wformat]
printf("p+2 = %08x\n",p+2);
~~~~ ^~~
repo.2.c:105:25: warning: format specifies type 'int' but the argument has type
'int *' [-Wformat]
printf("*(d+3) = %d\n",*(d+3));
~~ ^~~~~~
repo.2.c:107:27: warning: format specifies type 'int' but the argument has type
'int *' [-Wformat]
printf("*(d[1]+2) = %d\n",(d[1]+2));
~~ ^~~~~~~~
repo.2.c:111:24: error: use of undeclared identifier 'p'
char *str = "abcdefg" *p;
^
repo.2.c:112:1: error: use of undeclared identifier 'p'
p = str+3;
^
repo.2.c:114:19: error: use of undeclared identifier 'p'
printf("p = %s\n",p);
^
repo.2.c:154:6: warning: result of comparison against a string literal is
unspecified (use strncmp instead) [-Wstring-compare]
if(p == "abcd") x= 0;
^ ~~~~~~
警告やエラーが多すぎますがどうかよろしくお願いします。