![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
Dependencies: mbed NetEthApiLPC1768 NetServicesLPC1768
main.cpp@2:a44007a5c712, 2010-06-07 (annotated)
- Committer:
- nucho
- Date:
- Mon Jun 07 08:42:46 2010 +0000
- Revision:
- 2:a44007a5c712
- Parent:
- 1:e1bfb7d930e5
- Child:
- 3:d924cbf35c0f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:c6d1b3f0c307 | 1 | #include "mbed.h" |
nucho | 0:c6d1b3f0c307 | 2 | #include "TextLCD.h" |
nucho | 0:c6d1b3f0c307 | 3 | #include "EthernetNetIf.h" |
nucho | 0:c6d1b3f0c307 | 4 | #include "HttpClient.h" |
nucho | 0:c6d1b3f0c307 | 5 | |
nucho | 0:c6d1b3f0c307 | 6 | void free_member(struct member *p); |
nucho | 0:c6d1b3f0c307 | 7 | void print_member(struct member *p); |
nucho | 0:c6d1b3f0c307 | 8 | struct member *add_member(char *name, int id, struct member *head); |
nucho | 0:c6d1b3f0c307 | 9 | unsigned int readCard(); |
nucho | 0:c6d1b3f0c307 | 10 | struct member * search_id(struct member *p,unsigned int id); |
nucho | 0:c6d1b3f0c307 | 11 | struct member *create_member(void); |
nucho | 0:c6d1b3f0c307 | 12 | void LED_Bright(int led_num); |
nucho | 0:c6d1b3f0c307 | 13 | void LED_KnightRider(); |
nucho | 0:c6d1b3f0c307 | 14 | |
nucho | 0:c6d1b3f0c307 | 15 | using namespace std; |
nucho | 0:c6d1b3f0c307 | 16 | |
nucho | 0:c6d1b3f0c307 | 17 | EthernetNetIf eth; |
nucho | 0:c6d1b3f0c307 | 18 | HttpClient http; |
nucho | 0:c6d1b3f0c307 | 19 | |
nucho | 0:c6d1b3f0c307 | 20 | LocalFileSystem local("local"); |
nucho | 0:c6d1b3f0c307 | 21 | |
nucho | 0:c6d1b3f0c307 | 22 | Serial pc(USBTX, USBRX); // tx, rx |
nucho | 0:c6d1b3f0c307 | 23 | DigitalOut led1(LED1); |
nucho | 0:c6d1b3f0c307 | 24 | DigitalOut led2(LED2); |
nucho | 0:c6d1b3f0c307 | 25 | DigitalOut led3(LED3); |
nucho | 0:c6d1b3f0c307 | 26 | DigitalOut led4(LED4); |
nucho | 0:c6d1b3f0c307 | 27 | |
nucho | 0:c6d1b3f0c307 | 28 | Serial device(p13, p14); // tx, rx |
nucho | 0:c6d1b3f0c307 | 29 | InterruptIn button(p17); |
nucho | 0:c6d1b3f0c307 | 30 | DigitalIn irq(p19); |
nucho | 0:c6d1b3f0c307 | 31 | //DigitalOut rst(p20); |
nucho | 0:c6d1b3f0c307 | 32 | |
nucho | 1:e1bfb7d930e5 | 33 | //TextLCD lcd(p15, p9, p16, p8, p11, p7, p10); // rs, rw, e, d0, d1, d2, d3 |
nucho | 1:e1bfb7d930e5 | 34 | TextLCD lcd(p5, p6, p7, p8, p9, p10); // rs, rw, e, d0, d1, d2, d3 |
nucho | 0:c6d1b3f0c307 | 35 | |
nucho | 0:c6d1b3f0c307 | 36 | const char user[] = "your accout"; |
nucho | 0:c6d1b3f0c307 | 37 | const char pass[] = "yourt password"; |
nucho | 0:c6d1b3f0c307 | 38 | const char login_msg[] = " is login now."; |
nucho | 0:c6d1b3f0c307 | 39 | const char logout_msg[] = " is logout now."; |
nucho | 0:c6d1b3f0c307 | 40 | const char url[] = "http://twitter.com/statuses/update.xml"; |
nucho | 0:c6d1b3f0c307 | 41 | const char ntp_server[] = "http://ntp-a1.nict.go.jp/cgi-bin/ntp"; |
nucho | 0:c6d1b3f0c307 | 42 | bool card_flag=false; |
nucho | 0:c6d1b3f0c307 | 43 | |
nucho | 0:c6d1b3f0c307 | 44 | struct member { |
nucho | 0:c6d1b3f0c307 | 45 | char name[100]; |
nucho | 0:c6d1b3f0c307 | 46 | unsigned int id; |
nucho | 0:c6d1b3f0c307 | 47 | bool enter; |
nucho | 0:c6d1b3f0c307 | 48 | struct member *next; |
nucho | 0:c6d1b3f0c307 | 49 | }; |
nucho | 0:c6d1b3f0c307 | 50 | |
nucho | 0:c6d1b3f0c307 | 51 | void cardIRQ() { |
nucho | 0:c6d1b3f0c307 | 52 | card_flag=true; |
nucho | 0:c6d1b3f0c307 | 53 | } |
nucho | 0:c6d1b3f0c307 | 54 | |
nucho | 0:c6d1b3f0c307 | 55 | |
nucho | 0:c6d1b3f0c307 | 56 | int main() { |
nucho | 0:c6d1b3f0c307 | 57 | device.baud(19200); |
nucho | 0:c6d1b3f0c307 | 58 | pc.baud(9600); |
nucho | 0:c6d1b3f0c307 | 59 | printf("Init\n"); |
nucho | 0:c6d1b3f0c307 | 60 | lcd.printf("Init\n"); |
nucho | 0:c6d1b3f0c307 | 61 | char sendmsg[255]; |
nucho | 0:c6d1b3f0c307 | 62 | char buf[40]; |
nucho | 0:c6d1b3f0c307 | 63 | member *p=NULL; |
nucho | 0:c6d1b3f0c307 | 64 | member *head=NULL; |
nucho | 0:c6d1b3f0c307 | 65 | time_t seconds = time(NULL); |
nucho | 0:c6d1b3f0c307 | 66 | HttpClient twitter; |
nucho | 0:c6d1b3f0c307 | 67 | char *e; |
nucho | 0:c6d1b3f0c307 | 68 | char name[100]; |
nucho | 0:c6d1b3f0c307 | 69 | unsigned int id; |
nucho | 0:c6d1b3f0c307 | 70 | |
nucho | 0:c6d1b3f0c307 | 71 | HttpMap msg; |
nucho | 0:c6d1b3f0c307 | 72 | |
nucho | 0:c6d1b3f0c307 | 73 | //connect Ethernet |
nucho | 0:c6d1b3f0c307 | 74 | printf("\r\nSetting up...\r\n"); |
nucho | 0:c6d1b3f0c307 | 75 | EthernetErr ethErr = eth.setup(); |
nucho | 0:c6d1b3f0c307 | 76 | if (ethErr) { |
nucho | 0:c6d1b3f0c307 | 77 | printf("Error %d in setup.\n", ethErr); |
nucho | 0:c6d1b3f0c307 | 78 | return -1; |
nucho | 0:c6d1b3f0c307 | 79 | } |
nucho | 0:c6d1b3f0c307 | 80 | printf("\r\nSetup OK\r\n"); |
nucho | 0:c6d1b3f0c307 | 81 | |
nucho | 0:c6d1b3f0c307 | 82 | twitter.basicAuth(user, pass); //We use basic authentication, replace with you accoun |
nucho | 0:c6d1b3f0c307 | 83 | |
nucho | 0:c6d1b3f0c307 | 84 | //read member |
nucho | 0:c6d1b3f0c307 | 85 | pc.printf("Opening File...\n"); // Drive should be marked as removed |
nucho | 0:c6d1b3f0c307 | 86 | FILE *fp = fopen("/local/member.txt", "r"); |
nucho | 0:c6d1b3f0c307 | 87 | |
nucho | 0:c6d1b3f0c307 | 88 | while (fscanf( fp, "%[^,],%d\n",name, &id) != EOF ) { |
nucho | 0:c6d1b3f0c307 | 89 | head = add_member(name,id, head); |
nucho | 0:c6d1b3f0c307 | 90 | } |
nucho | 0:c6d1b3f0c307 | 91 | fclose(fp); |
nucho | 0:c6d1b3f0c307 | 92 | pc.printf("Opened.\n"); |
nucho | 0:c6d1b3f0c307 | 93 | |
nucho | 0:c6d1b3f0c307 | 94 | // Start RTC |
nucho | 0:c6d1b3f0c307 | 95 | lcd.printf("RTC setting...\n"); |
nucho | 0:c6d1b3f0c307 | 96 | HttpText txt; |
nucho | 0:c6d1b3f0c307 | 97 | |
nucho | 0:c6d1b3f0c307 | 98 | http.get(ntp_server, &txt); |
nucho | 0:c6d1b3f0c307 | 99 | int start_body=strstr(txt.gets(),"<BODY>")-txt.gets()+7; |
nucho | 0:c6d1b3f0c307 | 100 | int end_body = strstr(txt.gets(),"</BODY>")-txt.gets()-1; |
nucho | 0:c6d1b3f0c307 | 101 | strncpy(buf, txt.gets()+start_body, end_body-start_body); |
nucho | 0:c6d1b3f0c307 | 102 | |
nucho | 0:c6d1b3f0c307 | 103 | |
nucho | 0:c6d1b3f0c307 | 104 | //printf("<%s>\n",txt.gets()); |
nucho | 0:c6d1b3f0c307 | 105 | //printf("%lu\n",strtoul(buf,&e,10)); |
nucho | 0:c6d1b3f0c307 | 106 | seconds = strtoul(buf,&e,10)-2208988800UL+32400; |
nucho | 0:c6d1b3f0c307 | 107 | set_time(seconds); |
nucho | 0:c6d1b3f0c307 | 108 | |
nucho | 0:c6d1b3f0c307 | 109 | button.rise(&cardIRQ); |
nucho | 0:c6d1b3f0c307 | 110 | while (1) { |
nucho | 0:c6d1b3f0c307 | 111 | seconds = time(NULL); |
nucho | 0:c6d1b3f0c307 | 112 | strftime(buf,sizeof(buf),"%Y/%m/%d %a\n%H:%M:%S Ready!", localtime(&seconds)); |
nucho | 0:c6d1b3f0c307 | 113 | printf("%s\n", buf); |
nucho | 0:c6d1b3f0c307 | 114 | lcd.printf("%s", buf); |
nucho | 0:c6d1b3f0c307 | 115 | wait(0.3); |
nucho | 0:c6d1b3f0c307 | 116 | |
nucho | 0:c6d1b3f0c307 | 117 | if (card_flag) { |
nucho | 0:c6d1b3f0c307 | 118 | lcd.cls(); |
nucho | 0:c6d1b3f0c307 | 119 | strcpy(sendmsg,""); |
nucho | 0:c6d1b3f0c307 | 120 | |
nucho | 0:c6d1b3f0c307 | 121 | id= readCard(); |
nucho | 0:c6d1b3f0c307 | 122 | pc.printf("id=%u\n",id); |
nucho | 0:c6d1b3f0c307 | 123 | p = search_id(head,id);//checkID |
nucho | 0:c6d1b3f0c307 | 124 | |
nucho | 0:c6d1b3f0c307 | 125 | if (p!=NULL) {//list has same ID |
nucho | 0:c6d1b3f0c307 | 126 | pc.printf("%s\n",p->name); |
nucho | 0:c6d1b3f0c307 | 127 | |
nucho | 0:c6d1b3f0c307 | 128 | lcd.locate(0,0); |
nucho | 0:c6d1b3f0c307 | 129 | lcd.printf("%s",p->name); |
nucho | 0:c6d1b3f0c307 | 130 | lcd.locate(0,1); |
nucho | 0:c6d1b3f0c307 | 131 | lcd.printf("id=%u",p->id); |
nucho | 0:c6d1b3f0c307 | 132 | |
nucho | 0:c6d1b3f0c307 | 133 | strcat(sendmsg,p->name); |
nucho | 0:c6d1b3f0c307 | 134 | seconds = time(NULL); |
nucho | 0:c6d1b3f0c307 | 135 | strftime(buf,sizeof(buf), " (%Y/%m/%d %a %H:%M:%S)", localtime(&seconds)); |
nucho | 0:c6d1b3f0c307 | 136 | |
nucho | 0:c6d1b3f0c307 | 137 | if (p->enter) { |
nucho | 0:c6d1b3f0c307 | 138 | strcat(sendmsg,logout_msg); |
nucho | 0:c6d1b3f0c307 | 139 | strcat(sendmsg,buf); |
nucho | 0:c6d1b3f0c307 | 140 | pc.printf("%s\n",sendmsg); |
nucho | 0:c6d1b3f0c307 | 141 | msg["status"] = sendmsg; |
nucho | 0:c6d1b3f0c307 | 142 | twitter.post(url, msg, NULL); |
nucho | 0:c6d1b3f0c307 | 143 | |
nucho | 0:c6d1b3f0c307 | 144 | p->enter=false; |
nucho | 0:c6d1b3f0c307 | 145 | } else { |
nucho | 0:c6d1b3f0c307 | 146 | strcat(sendmsg,login_msg); |
nucho | 0:c6d1b3f0c307 | 147 | strcat(sendmsg,buf); |
nucho | 0:c6d1b3f0c307 | 148 | pc.printf("%s\n",sendmsg); |
nucho | 0:c6d1b3f0c307 | 149 | msg["status"] = sendmsg; |
nucho | 0:c6d1b3f0c307 | 150 | twitter.post(url, msg, NULL); |
nucho | 0:c6d1b3f0c307 | 151 | |
nucho | 0:c6d1b3f0c307 | 152 | p->enter=true; |
nucho | 0:c6d1b3f0c307 | 153 | } |
nucho | 0:c6d1b3f0c307 | 154 | LED_KnightRider(); |
nucho | 0:c6d1b3f0c307 | 155 | |
nucho | 0:c6d1b3f0c307 | 156 | card_flag=false; |
nucho | 0:c6d1b3f0c307 | 157 | lcd.cls(); |
nucho | 0:c6d1b3f0c307 | 158 | } else { |
nucho | 0:c6d1b3f0c307 | 159 | lcd.locate(0,0); |
nucho | 0:c6d1b3f0c307 | 160 | lcd.printf("You are'nt member"); |
nucho | 0:c6d1b3f0c307 | 161 | lcd.locate(0,1); |
nucho | 0:c6d1b3f0c307 | 162 | lcd.printf("id=%u",p->id); |
nucho | 0:c6d1b3f0c307 | 163 | wait(1); |
nucho | 2:a44007a5c712 | 164 | card_flag=false; |
nucho | 2:a44007a5c712 | 165 | lcd.cls(); |
nucho | 0:c6d1b3f0c307 | 166 | } |
nucho | 0:c6d1b3f0c307 | 167 | |
nucho | 0:c6d1b3f0c307 | 168 | } |
nucho | 0:c6d1b3f0c307 | 169 | |
nucho | 0:c6d1b3f0c307 | 170 | } |
nucho | 0:c6d1b3f0c307 | 171 | } |
nucho | 0:c6d1b3f0c307 | 172 | |
nucho | 0:c6d1b3f0c307 | 173 | void LED_KnightRider() { |
nucho | 0:c6d1b3f0c307 | 174 | LED_Bright(1); |
nucho | 0:c6d1b3f0c307 | 175 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 176 | LED_Bright(2); |
nucho | 0:c6d1b3f0c307 | 177 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 178 | LED_Bright(3); |
nucho | 0:c6d1b3f0c307 | 179 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 180 | LED_Bright(4); |
nucho | 0:c6d1b3f0c307 | 181 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 182 | LED_Bright(3); |
nucho | 0:c6d1b3f0c307 | 183 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 184 | LED_Bright(2); |
nucho | 0:c6d1b3f0c307 | 185 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 186 | LED_Bright(1); |
nucho | 0:c6d1b3f0c307 | 187 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 188 | LED_Bright(0); |
nucho | 0:c6d1b3f0c307 | 189 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 190 | LED_Bright(1); |
nucho | 0:c6d1b3f0c307 | 191 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 192 | LED_Bright(2); |
nucho | 0:c6d1b3f0c307 | 193 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 194 | LED_Bright(3); |
nucho | 0:c6d1b3f0c307 | 195 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 196 | LED_Bright(4); |
nucho | 0:c6d1b3f0c307 | 197 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 198 | LED_Bright(3); |
nucho | 0:c6d1b3f0c307 | 199 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 200 | LED_Bright(2); |
nucho | 0:c6d1b3f0c307 | 201 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 202 | LED_Bright(1); |
nucho | 0:c6d1b3f0c307 | 203 | wait(0.05); |
nucho | 0:c6d1b3f0c307 | 204 | LED_Bright(0); |
nucho | 0:c6d1b3f0c307 | 205 | } |
nucho | 0:c6d1b3f0c307 | 206 | |
nucho | 0:c6d1b3f0c307 | 207 | void LED_Bright(int led_num) { |
nucho | 0:c6d1b3f0c307 | 208 | switch (led_num) { |
nucho | 0:c6d1b3f0c307 | 209 | case 1: |
nucho | 0:c6d1b3f0c307 | 210 | led1=1; |
nucho | 0:c6d1b3f0c307 | 211 | led2=0; |
nucho | 0:c6d1b3f0c307 | 212 | led3=0; |
nucho | 0:c6d1b3f0c307 | 213 | led4=0; |
nucho | 0:c6d1b3f0c307 | 214 | break; |
nucho | 0:c6d1b3f0c307 | 215 | case 2: |
nucho | 0:c6d1b3f0c307 | 216 | led1=0; |
nucho | 0:c6d1b3f0c307 | 217 | led2=1; |
nucho | 0:c6d1b3f0c307 | 218 | led3=0; |
nucho | 0:c6d1b3f0c307 | 219 | led4=0; |
nucho | 0:c6d1b3f0c307 | 220 | break; |
nucho | 0:c6d1b3f0c307 | 221 | case 3: |
nucho | 0:c6d1b3f0c307 | 222 | led1=0; |
nucho | 0:c6d1b3f0c307 | 223 | led2=0; |
nucho | 0:c6d1b3f0c307 | 224 | led3=1; |
nucho | 0:c6d1b3f0c307 | 225 | led4=0; |
nucho | 0:c6d1b3f0c307 | 226 | break; |
nucho | 0:c6d1b3f0c307 | 227 | case 4: |
nucho | 0:c6d1b3f0c307 | 228 | led1=0; |
nucho | 0:c6d1b3f0c307 | 229 | led2=0; |
nucho | 0:c6d1b3f0c307 | 230 | led3=0; |
nucho | 0:c6d1b3f0c307 | 231 | led4=1; |
nucho | 0:c6d1b3f0c307 | 232 | break; |
nucho | 0:c6d1b3f0c307 | 233 | default: |
nucho | 0:c6d1b3f0c307 | 234 | led1=0; |
nucho | 0:c6d1b3f0c307 | 235 | led2=0; |
nucho | 0:c6d1b3f0c307 | 236 | led3=0; |
nucho | 0:c6d1b3f0c307 | 237 | led4=0; |
nucho | 0:c6d1b3f0c307 | 238 | break; |
nucho | 0:c6d1b3f0c307 | 239 | } |
nucho | 0:c6d1b3f0c307 | 240 | } |
nucho | 0:c6d1b3f0c307 | 241 | |
nucho | 0:c6d1b3f0c307 | 242 | |
nucho | 0:c6d1b3f0c307 | 243 | unsigned int readCard() { |
nucho | 0:c6d1b3f0c307 | 244 | unsigned int id=0; |
nucho | 0:c6d1b3f0c307 | 245 | int len,i; |
nucho | 0:c6d1b3f0c307 | 246 | |
nucho | 0:c6d1b3f0c307 | 247 | device.getc();//header |
nucho | 0:c6d1b3f0c307 | 248 | device.getc();//header |
nucho | 0:c6d1b3f0c307 | 249 | len = device.getc(); |
nucho | 0:c6d1b3f0c307 | 250 | |
nucho | 0:c6d1b3f0c307 | 251 | char data[len]; |
nucho | 0:c6d1b3f0c307 | 252 | for (i=0;i<len;i++) { |
nucho | 0:c6d1b3f0c307 | 253 | data[i]=device.getc(); |
nucho | 0:c6d1b3f0c307 | 254 | } |
nucho | 0:c6d1b3f0c307 | 255 | if (data[0]==0x50) {//success |
nucho | 0:c6d1b3f0c307 | 256 | for (i=0;i<4;i++) { |
nucho | 0:c6d1b3f0c307 | 257 | id |= (data[4-i] << (i * 8)); |
nucho | 0:c6d1b3f0c307 | 258 | } |
nucho | 0:c6d1b3f0c307 | 259 | } else {//failre |
nucho | 0:c6d1b3f0c307 | 260 | } |
nucho | 0:c6d1b3f0c307 | 261 | |
nucho | 0:c6d1b3f0c307 | 262 | return id; |
nucho | 0:c6d1b3f0c307 | 263 | } |
nucho | 0:c6d1b3f0c307 | 264 | |
nucho | 0:c6d1b3f0c307 | 265 | void print_member(struct member *p) { |
nucho | 0:c6d1b3f0c307 | 266 | while (p != NULL) { |
nucho | 0:c6d1b3f0c307 | 267 | pc.printf("%s %u\n", p->name,p->id); |
nucho | 0:c6d1b3f0c307 | 268 | p = p->next; |
nucho | 0:c6d1b3f0c307 | 269 | } |
nucho | 0:c6d1b3f0c307 | 270 | } |
nucho | 0:c6d1b3f0c307 | 271 | |
nucho | 0:c6d1b3f0c307 | 272 | void free_member(struct member *p) { |
nucho | 0:c6d1b3f0c307 | 273 | struct member *p2; |
nucho | 0:c6d1b3f0c307 | 274 | |
nucho | 0:c6d1b3f0c307 | 275 | while (p != NULL) { |
nucho | 0:c6d1b3f0c307 | 276 | p2 = p->next; |
nucho | 0:c6d1b3f0c307 | 277 | free(p); |
nucho | 0:c6d1b3f0c307 | 278 | p = p2; |
nucho | 0:c6d1b3f0c307 | 279 | } |
nucho | 0:c6d1b3f0c307 | 280 | } |
nucho | 0:c6d1b3f0c307 | 281 | |
nucho | 0:c6d1b3f0c307 | 282 | |
nucho | 0:c6d1b3f0c307 | 283 | struct member *add_member(char *name, int id, struct member *head) { |
nucho | 0:c6d1b3f0c307 | 284 | struct member *p; |
nucho | 0:c6d1b3f0c307 | 285 | |
nucho | 0:c6d1b3f0c307 | 286 | p=create_member(); |
nucho | 0:c6d1b3f0c307 | 287 | p->id = id; |
nucho | 0:c6d1b3f0c307 | 288 | strcpy(p->name, name); |
nucho | 0:c6d1b3f0c307 | 289 | |
nucho | 0:c6d1b3f0c307 | 290 | p->next = head; |
nucho | 0:c6d1b3f0c307 | 291 | head = p; |
nucho | 0:c6d1b3f0c307 | 292 | |
nucho | 0:c6d1b3f0c307 | 293 | return head; |
nucho | 0:c6d1b3f0c307 | 294 | } |
nucho | 0:c6d1b3f0c307 | 295 | |
nucho | 0:c6d1b3f0c307 | 296 | struct member *create_member(void) { |
nucho | 0:c6d1b3f0c307 | 297 | struct member *p; |
nucho | 0:c6d1b3f0c307 | 298 | |
nucho | 0:c6d1b3f0c307 | 299 | if ((p = (struct member *) malloc(sizeof(struct member))) == NULL) { |
nucho | 0:c6d1b3f0c307 | 300 | printf("malloc error\n"); |
nucho | 0:c6d1b3f0c307 | 301 | exit(EXIT_FAILURE); |
nucho | 0:c6d1b3f0c307 | 302 | } |
nucho | 0:c6d1b3f0c307 | 303 | p->enter = false; |
nucho | 0:c6d1b3f0c307 | 304 | |
nucho | 0:c6d1b3f0c307 | 305 | return p; |
nucho | 0:c6d1b3f0c307 | 306 | } |
nucho | 0:c6d1b3f0c307 | 307 | |
nucho | 0:c6d1b3f0c307 | 308 | struct member * search_id(struct member *p,unsigned int id) { |
nucho | 0:c6d1b3f0c307 | 309 | struct member *findp=NULL; |
nucho | 0:c6d1b3f0c307 | 310 | while (p != NULL) { |
nucho | 0:c6d1b3f0c307 | 311 | if (p->id==id) { |
nucho | 0:c6d1b3f0c307 | 312 | findp = p; |
nucho | 0:c6d1b3f0c307 | 313 | break; |
nucho | 0:c6d1b3f0c307 | 314 | } |
nucho | 0:c6d1b3f0c307 | 315 | p = p->next; |
nucho | 0:c6d1b3f0c307 | 316 | } |
nucho | 0:c6d1b3f0c307 | 317 | return findp; |
nucho | 0:c6d1b3f0c307 | 318 | } |