-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers.c
More file actions
64 lines (53 loc) · 1.24 KB
/
pointers.c
File metadata and controls
64 lines (53 loc) · 1.24 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
/*
pointers.c
By David Broman.
Last modified: 2015-09-15
This file is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
char* text1 = "This is a string.";
char* text2 = "Yet another thing.";
void printlist(const int* lst){
printf("ASCII codes and corresponding characters.\n");
while(*lst != 0){
printf("0x%03X '%c' ", *lst, (char)*lst);
lst++;
}
printf("\n");
}
void endian_proof(const char* c){
printf("\nEndian experiment: 0x%02x,0x%02x,0x%02x,0x%02x\n",
(int)*c,(int)*(c+1), (int)*(c+2), (int)*(c+3));
}
// Skriven av KI
void copycodes(char* text, int* list, int* counter) {
if (*text != 0) {
*list = *text;
text++;
list++;
*counter += 1; // *counter++; funkar inte?
copycodes(text, list, counter);
}
}
// Skriven av KI
void work(int* list1, int* list2, int* counter) {
copycodes(text1, list1, counter);
copycodes(text2, list2, counter);
}
int main(void){
// Skriven av KI
int* list1 = malloc(80);
int* list2 = malloc(80);
int counter = 0;
work(list1, list2, &counter);
printf("\nlist1: ");
printlist(list1);
printf("\nlist2: ");
printlist(list2);
printf("\nCount = %d\n", counter);
// Skriven av KI
free(list1);
free(list2);
endian_proof((char*) &counter);
}