因為這次要寫的 51 圖形的LCD控制
看範例發現大家都是用指標去寫的@@?
奇怪 單晶片可以用到指標@@?
那指標的組語怎麼寫@@?
所以就向俊x大大問指標的事情
沒想到俊x大大就大方的借我一本指標的書
但借我看書不是沒有回報的
俊x : 那你把 linked list 寫出來看看
看了無數的範例後 發現這個範例我最懂
所以就 兩天把它趕出來了
途中要謝謝阿福大大 說知識+有
自已看
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
char data;
struct node *next;
}node;
int main(void)
{
node *head = NULL;
node *ptr;
node *next_node;
int i;
char input;
for (i = 0;i < 5;i++)
{
fflush(stdin);
scanf("%c",&input);
next_node = (node*)malloc(sizeof(node));
if (!next_node) //不能配到記憶體 則跳開
{
exit(1);
}
next_node->data = input;
if (head == NULL) //head 放到第一個node
{
head = next_node;
next_node->next = NULL;
}
else
{
for (ptr = head;ptr->next != NULL;ptr=ptr->next); //走訪node 一直找下一個node
ptr->next=next_node;
next_node->next=NULL;
}
}
for (ptr = head;ptr != NULL;ptr=ptr->next) //printf all node
printf("%c",ptr->data);
free(next_node);
system("pause");
}
懂了
就不難...
請先 登入 以發表留言。