포인터 배열

C : 2007. 11. 3. 11:49
 

int *pa[20]; ->정수형 포인터 배열 선언

pa[8]=&myvar; ->myvar라는 정수형 변수의 주소를 배열에 치환할수 있다.

*pa[2] = 100; ->pa의 세번째 원소가 가리키는 정수에 100을 치환한다.


p.216_1
#include <stdio.h>
#include <string.h>

char *p[][2] = {               //언사이즈드 배열
 "Red Delicious", "red",
 "Golden Delicious", "yellow",
 "Winesap", "red",
 "Gala", "reddish orange",
 "Lodi", "green",
 "Mutsu", "yellow",
 "Cortland", "red",
 "Jonathan", "red",
 "", ""
};


int main(void)
{
 int i;
 char apple[80];

 printf("enter name of apple: ");
 gets(apple);

 for(i=0; *p[i][0]; i++) {             //(i+1)번째 문자열의 첫번째 바이트의 문자를 얻는식
  if(!strcmp(apple, p[i][0]))
   printf("%s is %s\n", apple, p[i][1]);
 }
 return 0;
}

Posted by 청웨일