-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
64 lines (58 loc) · 1.08 KB
/
main.c
File metadata and controls
64 lines (58 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node
{
int value;
struct Node* next;
} List;
List* init(int value)
{
List* head = (List*)malloc(sizeof(List));
head->next = NULL;
head->value = value;
return head;
}
void add(int value, List *head)
{
List* temp = head;
while(temp->next != NULL)
{
temp = temp->next;
}
List* new_node = (List*)malloc(sizeof(List));;
new_node->next = NULL;
new_node->value = value;
temp->next = new_node;
}
void ls(List* head)
{
List* temp = (List*)malloc(sizeof(List));
temp = head;
while(temp != NULL)
{
printf("%d\n",temp->value);
temp = temp->next;
}
free(temp);
}
int get_by_index(List* head, int pos)
{
List* temp = head;
while(pos-- && head->next != NULL)
{
temp = temp->next;
}
return temp->value;
}
int main()
{
char str[] = "Hello GitHub!";
char *fortok = strtok(str, " ");
while(fortok != NULL)
{
printf("%s",fortok);
fortok = strtok(NULL, " ");
}
return 0;
}