This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2020:cprog:projects:cbf0 [2020/09/28 18:34] – wedge | haas:fall2020:cprog:projects:cbf0 [2020/09/29 15:02] (current) – [Experiencing xxd] wedge | ||
---|---|---|---|
Line 183: | Line 183: | ||
<cli> | <cli> | ||
+ | system: | ||
00000000: 3e 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f > | 00000000: 3e 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f > | ||
00000010: 50 51 52 53 54 55 56 57 58 59 5a 3c 0a 5b 61 62 PQRSTUVWXYZ< | 00000010: 50 51 52 53 54 55 56 57 58 59 5a 3c 0a 5b 61 62 PQRSTUVWXYZ< | ||
Line 194: | Line 195: | ||
00000090: 45 46 3a 48 45 58 41 44 45 43 49 4d 41 4c 0a 29 EF: | 00000090: 45 46 3a 48 45 58 41 44 45 43 49 4d 41 4c 0a 29 EF: | ||
000000a0: 21 40 23 24 25 5e 26 2a 28 0a 2e 0a !@# | 000000a0: 21 40 23 24 25 5e 26 2a 28 0a 2e 0a !@# | ||
+ | </ | ||
+ | |||
+ | Or, if using a line throttle: | ||
+ | |||
+ | <cli> | ||
+ | system: | ||
+ | 00000000: 3e 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f > | ||
+ | 00000010: 50 51 52 53 54 55 56 57 58 59 5a 3c 0a 5b 61 62 PQRSTUVWXYZ< | ||
+ | 00000020: 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 cdefghijklmnopqr | ||
+ | 00000030: 73 74 75 76 77 78 79 7a 5d 0a 30 31 3a 20 20 20 stuvwxyz].01: | ||
</ | </ | ||
=====Detecting Terminal Size===== | =====Detecting Terminal Size===== | ||
Line 221: | Line 232: | ||
Compile and run the above code to see how it works. Try it in different size terminals. Then incorporate the logic into your hex viewer for this project. | Compile and run the above code to see how it works. Try it in different size terminals. Then incorporate the logic into your hex viewer for this project. | ||
+ | |||
+ | =====Command-Line Arguments===== | ||
+ | |||
+ | ====setting up main()==== | ||
+ | To accept (or rather, to gain access) to arguments given to your program at runtime, we need to specify two parameters to the main() function. While the names don't matter, the types do.. I like the traditional **argc** and **argv** names, although it is also common to see them abbreviated as **ac** and **av**. | ||
+ | |||
+ | Please declare your main() function as follows: | ||
+ | |||
+ | <code c> | ||
+ | int main(int argc, char **argv) | ||
+ | </ | ||
+ | |||
+ | There are two very important variables involved here (the types are actually what are important, the names given to the variables are actually quite, variable; you may see other references refer to them as things like " | ||
+ | |||
+ | * int argc: the count (an integer) of tokens given on the command line (program name + arguments) | ||
+ | * < | ||
+ | |||
+ | The arguments are accessible via the argv array, in the order they were specified: | ||
+ | |||
+ | * argv[0]: program invocation (path + program name) | ||
+ | * argv[1]: our first argument | ||
+ | * argv[2]: second argument | ||
+ | * argv[3]: third argument | ||
+ | * ... | ||
+ | * argv[N]: Nth argument | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | ===example=== | ||
+ | For example, if we were to execute a program as follows: | ||
+ | |||
+ | <cli> | ||
+ | $ ./program word 73 another word | ||
+ | </ | ||
+ | |||
+ | We'd have: | ||
+ | |||
+ | * < | ||
+ | * < | ||
+ | * < | ||
+ | * < | ||
+ | * < | ||
+ | |||
+ | and let's not forget: | ||
+ | |||
+ | * argc: 5 | ||
=====Loops===== | =====Loops===== |