This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:spring2020:cprog:projects:dtr0 [2018/08/19 16:10] – external edit 127.0.0.1 | haas:spring2020:cprog:projects:dtr0 [2020/01/26 22:46] (current) – [Submit Tool Usage] wedge | ||
---|---|---|---|
Line 22: | Line 22: | ||
=====Scope===== | =====Scope===== | ||
- | This project will be exploring the nature of some of the data types available to us in the C Programming Language. How much space is allocated to each type, how many numbers can exist within | + | This project will be exploring the nature of some of the data types available to us in the C Programming Language. How much space is allocated to each type, and what are the ranges available for each type? |
- | A program | + | A program |
The data types covered for this project will include **signed** and **unsigned** variations of: | The data types covered for this project will include **signed** and **unsigned** variations of: | ||
Line 36: | Line 36: | ||
The **sizeof()** and **printf()** functions, as well as arithmetic and logical operators, will be utilized in performing much of the work. | The **sizeof()** and **printf()** functions, as well as arithmetic and logical operators, will be utilized in performing much of the work. | ||
- | =====Code===== | + | =====Grabbing project resources===== |
+ | I have prepared a **grabit** for resources related to this project. To obtain: | ||
- | ====Skeleton Program==== | + | <cli> |
- | Here is the skeleton of a program you'll want to use for this project: | + | lab46: |
+ | make: Entering directory | ||
+ | '/ | ||
+ | '/ | ||
+ | make: Leaving directory '/ | ||
+ | lab46: | ||
+ | </ | ||
- | <code c> | + | At which point you can change into the newly created |
- | /* | + | |
- | * dtr0.c - A program to derive and display information | + | |
- | | + | |
- | * | + | |
- | * | + | |
- | * A program by NAME for COURSENUMBER COURSENAME (SEMESTER) | + | |
- | * | + | |
- | * Compile with: gcc -o dtr0 dtr0.c | + | |
- | * Execute with: ./dtr0 | + | |
- | */ | + | |
- | + | ||
- | #include <stdio.h> | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | // Variables | + | |
- | unsigned char uchr = 0; | + | |
- | + | ||
- | // Code for unsigned char | + | |
- | + | ||
- | // Code for signed char | + | |
- | + | ||
- | // Code for unsigned short int | + | |
- | + | ||
- | // Code for signed short int | + | |
- | + | ||
- | // Code for unsigned int | + | |
- | + | ||
- | // Code for signed int | + | |
- | + | ||
- | // Code for unsigned long int | + | |
- | + | ||
- | // Code for signed long int | + | |
- | + | ||
- | // Code for unsigned long long int | + | |
- | + | ||
- | // Code for signed long long int | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
- | </ | + | |
- | ====unsigned char code block==== | + | Please study the **dtr0.c** program, and look up or ask questions on aspects that you do not understand. |
- | Following is provided code giving you the requested information for an **unsigned char**. Study it, implement it, and adapt it as needed to the other data types: | + | |
- | <code c> | + | Compile |
- | // Code for unsigned char | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | uchr = uchr - 1; // What does this line do? | + | |
- | fprintf(stdout, | + | |
- | </ | + | |
- | + | ||
- | Note that by adapting, you'll need to declare and initialize additional variables, and you may " | + | |
=====Execution===== | =====Execution===== | ||
<cli> | <cli> | ||
lab46: | lab46: | ||
- | TYPE: unsigned char, bytes: 1, low: 0, high: 255, qty: 256 | ||
- | TYPE: | ||
- | TYPE: unsigned short int, bytes: X, low: X, high: X, qty: X | ||
- | TYPE: | ||
- | ... | ||
- | lab46: | ||
</ | </ | ||
- | |||
- | This output includes some mock additional entries, actual values abstracted. Instead of displaying ' | ||
=====Reflection===== | =====Reflection===== | ||
Be sure to provide any commentary on your journal regarding realizations had and discoveries made during your pursuit of this project. You should also consider adding extra comments into your program so that it can be a more valuable reference going forward. | Be sure to provide any commentary on your journal regarding realizations had and discoveries made during your pursuit of this project. You should also consider adding extra comments into your program so that it can be a more valuable reference going forward. | ||
- | Also, answer | + | =====Your task===== |
+ | You are to create a text file, called " | ||
* What two data types appeared "the same"? | * What two data types appeared "the same"? | ||
- | * Why may this may be? | + | * Why is this the case? |
- | * Is this universal for all systems, or just a certain subset? | + | |
* With respect to **printf()**: | * With respect to **printf()**: | ||
* What is the difference between **printf()** and **fprintf()**? | * What is the difference between **printf()** and **fprintf()**? | ||
Line 125: | Line 72: | ||
* What is the difference between **%s**, **%hhu**, **%hu**? | * What is the difference between **%s**, **%hhu**, **%hu**? | ||
* How about **%u** and **%d**? | * How about **%u** and **%d**? | ||
- | * What does the **13** in **%13s** do for us? | + | * What does the **22** in **%22s** do for us? |
* If sign was left unspecified, | * If sign was left unspecified, | ||
* What are the **< | * What are the **< | ||
- | * How did they help you achieve | + | * What are they doing to enable |
- | * If you experienced trouble displaying | + | |
* Based on your program' | * Based on your program' | ||
* signed char | * signed char | ||
Line 193: | Line 139: | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
Submitting cprog project " | Submitting cprog project " | ||
- | -> dtr0.c(OK) | + | -> dtr0.text(OK) |
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED | ||
Line 206: | Line 152: | ||
< | < | ||
- | 39:dtr0:final tally of results (39/39) | + | 13:dtr0:final tally of results (13/13) |
- | *: | + | *: |
- | *: | + | *: |
- | *: | + | *: |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *:dtr0:no compiler warnings nor errors for dtr0.c [4/4] | + | |
</ | </ | ||