The creation of the program called size.c.
This is significant because you can determine your current character sizes, in bytes, based upon your current working console.
My code for the program below:#include<stdio.h> #include<stdlib.h> int main() { unsigned short int usi=0; unsigned int ui=0; unsigned long int uli=0; unsigned long long int ulli=0; unsigned char uc=0; // char is 8 bits (256 bits, 0-255) unsigned char carry=0; unsigned char quantity=0; quantity =uc-1; uc=quantity+1; if (uc<quantity) carry=1; else carry=0; // printing values of short int printf("unsigned short is %d bytes\n", sizeof(unsigned short int)); printf("usi low value is: %hx\n", usi); printf("usi high value is: %hx\n", (usi-1)); printf("unsigned short int unique values is: %hx%.2hx\n", carry, uc); printf(" \n"); // printing values of int printf("unsigned int is %d bytes\n", sizeof(unsigned int)); printf("ui low value is: %x\n", ui); printf("ui high value is: %x\n", (ui-1)); printf("unsigned char unique values is: %x%.2x\n", carry, uc); printf(" \n"); // printing values of long int printf("unsigned long int is %d bytes\n", sizeof(unsigned long int)); printf("uli low value is: %lx\n", uli); printf("uli high value is: %lx\n", (uli-1)); printf("unsigned char unique values is: %lxx%.2lxx\n", carry, uc); printf(" \n"); // printing values of long long int printf("unsigned long long int is %d bytes\n", sizeof(unsigned long long int)); printf("ulli low value is: %llx\n", ulli); printf("ulli high value is: %llx\n", (ulli-1)); printf("unsigned char unique values is: %llxx%.2llxx\n", carry, uc); printf(" \n"); // printing values of char printf("unsigned char is %d bytes\n", sizeof(unsigned char)); printf("uc low value is: %hhx\n", uc); printf("uc high value is: %hhx\n", (uc-1)); printf("unsigned char unique values is: %hhx%.2hhx\n", carry, uc); return(0); }
Concepts that do not make perfect sense currently are the %endings to each character.
Presenting the unique values for each character based on demand for it.
* What action or concept of significance, as related to the course, did you experience on this date?
Created a program called pointers.c
The code for this program is below:
#include<stdio.h> #include<stdlib.h> int main() { int a=12; int *b; b=&a; // changing values can lead to segmentation faults ex) b=2600 printf("a is located at 0x%X\n", &a); printf("b is located at 0x%X\n", &b); printf("b, when dereferenced, points to %d\n", *b); // dereference= a value printf("b contains 0x%X\n", b); return(0); }
* Why was this significant?
The significance of this program that is shows how the use of pointers work in use.
* What concepts are you dealing with that may not make perfect sense?
The "0x%", I don't fully understand what this is trying to accomplish.
* What challenges are you facing with respect to the course?
How exactly & work, and how to use them efficiently.
What action or concept of significance, as related to the course, did you experience on this date?
Created my own program that showed the relations to my logic choosing, based around the thought of converse implication.
My code for my logic program: (called ctruth.c)
#include <stdio.h> #include<stdlib.h> int main() { char logicor(char, char); int p = 0; int q = 0; int XNq(int p, int q); int result = 0; if ((p = 0) || (q = 0)); result = 0; if ((p = 0) || (q = 1)); result = 1; printf(" \n"); printf("Your Converse Implication Truth Table.\n"); printf(" \n"); printf("P | Q | XNq \n"); printf("_ _ _ _ _ \n"); q = 0; printf("%d | %d | %d \n", p, q, (p, q)); // all 0's q = 1; printf("%d | %d | %d \n", p, q, (q, p)); // when Q is false p = 0; printf("%d | %d | %d \n", q, p, (q, q)); // when Q is True p = 1; printf("%d | %d | %d \n", q, p, (p, 0)); // when P is False printf(" \n"); printf("Please enter the value for P: \n"); scanf("%d", &p); getchar(); printf("Please enter the value for Q: \n"); scanf("%d", &q); getchar(); putchar() printf(" \n"); if (p != q) { printf("Converse Implication Result.\n"); printf("F | T | F \n", p, q, (q, p)); printf(" \n"); } else (p + !q); { printf("Other Results.\n"); printf("T | T | T \n", p, q, (p, q)); printf("T | F | T \n", q, p, (p, q)); printf("F | F | T \n", q, p, (p, q)); } int XNq(int p, int q); return (0); }
Why was this significant?
This was significant because it was a project needed to be done for a grade.
What concepts are you dealing with that may not make perfect sense?
The concepts of printf syntax of formatting a line.
What challenges are you facing with respect to the course?
The understanding of pointers and how to use them effectively.
What action or concept of significance, as related to the course, did you experience on this date?
Learned about pre-processing directories, including the #include and #define, #ifdef, #endif.
Why was this significant?
These are used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to perform specific actions.
What concepts are you dealing with that may not make perfect sense?
Which directories to use to execute a certain function correctly.
What challenges are you facing with respect to the course?
Syntax involved with the typedef keyword.
Holds the address of another variable.
Void Pointers
The void pointer is a generic pointer type. A pointer to void can store an address to any non-function data type, and, in C is implicitly converted to any other pointer type on assignment, but it must be explicitly cast if dereferenced inline.
Dynamic Memory Allocation (Malloc/Free)
Dynamic memory allocation is the task of allocating a free chunk of memory specific to the size you predetermine in bytes, by using the malloc function. The chunk of memory is not always in the same location hence being “dynamic” instead of static. By using the “free” function, that will release the block of memory back to the system.
/* * Sample code block */ #include<stdio.h> #include<stdlib.h> struct node { char value; struct node *next; }; typedef struct node Node; int main() { Node *start, *tmp, *tmp2; // Node pointers char input, i = 0; start = tmp = tmp2 = NULL; printf("Enter a value (-1 to end): "); scanf("%hhd", &input); while (input != -1) // input does not equal -1 { if (start == NULL) { tmp = tmp2 = start = (Node *) malloc(sizeof(Node)); //allocating the size of the node start->value = input; start->next = NULL; // Starts next element is null } else { tmp->next = (Node *) malloc(sizeof(Node)); tmp->next->value = input; //tmp next value= new node(user input) tmp->next->next = NULL; //tmp next next =NULL tmp = tmp->next; } printf("Enter a value (-1 to quit): "); scanf("%hhd", &input); } tmp = start; i=0; while (tmp != NULL) //tmp does not equal NULL { printf("(%hhd)%hhd -> ",i, tmp->value); // print currrent value at node tmp = tmp->next; i = i + 1; } printf("NULL\n"); printf("Enter node # to delete: "); scanf("%hhd", &input); tmp = start; if (input != 0) { for (i = 0; i < input -1; i++) tmp = tmp->next; tmp2 = tmp -> next; tmp -> next = tmp -> next -> next; tmp2 -> next = NULL; free (tmp2); } else { start = start -> next; tmp -> next = NULL; free(tmp); } tmp=start; i=0; while (tmp != NULL) //tmp does not equal NULL { printf("(%hhd)%hhd -> ",i, tmp->value); // print currrent value at node tmp = tmp->next; i = i + 1; } printf("NULL\n"); return (0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src/data/Linked_List lab46:~/src/data/Linked_List$ ls lab46:~/src/data/Linked_List$ append append.c insert insertion.c link linked.c linkedlist.h node node.c remove remove.c lab46:~/src/data/Linked_List$ ./remove Enter a value (-1 to end): 1 Enter a value (-1 to quit): 2 Enter a value (-1 to quit): 3 Enter a value (-1 to quit): 4 Enter a value (-1 to quit): 5 Enter a value (-1 to quit): -1 (0)1 -> (1)2 -> (2)3 -> (3)4 -> (4)5 -> NULL Enter node # to delete: 3 (0)1 -> (1)2 -> (2)3 -> (3)5 -> NULL lab46:~/src/data/Linked_List$
For any two propositions P and Q, if Q implies P, then P is the converse implication of Q.
It may take the following forms:
P | Q | XNq _ _ _ _ _ 0 | 0 | 0 0 | 1 | 0 1 | 0 | 1 1 | 1 | 0
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Nonconjunction/Not Both … And.
The relation among the components of such a proposition, usually expressed by AND or & or ·
Left Projection
The left-shift operator causes the bit pattern in the first operand to be shifted to the left by the number of bits specified by the second operand. The value of a left-shift expression x « y is x * 2y
/* * Sample code block */ #include <stdio.h> int main() { unsigned int i; int j; int input; i = 1; printf("Enter a number to end your projection on: "); scanf("%d", &input); for(j = 0; j < input ; j++) { i = i << 1; printf("Left shift %d: %d(%X)\n", j, i); } return (0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd ./src/discrete lab46:~/src/discrete$ ls big bigl bigl.c bignum.c bit bitwise.c ctruth ctruth.c inc inc.c sets.c sort sort.c lab46:~/src/discrete$ ./bit Enter a number to end your projection on: // Choose any number here \\ 9 Left shift 0: 2(0) Left shift 1: 4(1) Left shift 2: 8(2) Left shift 3: 16(3) Left shift 4: 32(4) Left shift 5: 64(5) Left shift 6: 128(6) Left shift 7: 256(7) Left shift 8: 512(8)
Numbers in ( ) represent hexadecimal format, for when it becomes applicable at larger projection numbers.
What is the question you'd like to pose for experimentation? State it here.
Are there other escape sequences to meet a variance of needs, other than (\n) for a new line?
Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.
Chapter 2: Types, Operators, and Expressions. The C Programming Language Book.
Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.
I believe the result of my experiment go as I intend it to end, by that I mean that the proper escape sequence will do its function.
State your rationale.
My rationale for this would be that my trust in the program will run correctly, not segmentation faults or anything controversial to the situation.
How are you going to test your hypothesis? What is the structure of your experiment?
I am going to test my hypothesis by writing that program that will use some of the escape sequences. My data will show whether or not these escape sequences worked correctly or not. The structure of my program will be a line of printf statements using a certain escape sequence.
Perform your experiment, and collect/document the results here.
"The complete set of escape sequences is: " \a alert (bell) character \\ backlash \b backspace \? question mark \f formfeed \' single quote \n newline \" double quote \c carriage return \ooo octal number \t horizontal tab \xhh hexadecimal number \v vertical tab
Code for such program below:
#include <stdio.h> #include <stdlib.h> main () { int input; printf("Hello There\a -> alert (bell) character\n"); printf("Hello There\b -> backspace\n"); printf("Hello There\f -> formfeed\n"); printf("Hello There\n -> newline\n"); printf("Hello There\t -> horizontal tab\n"); printf("Hello There\v -> vertical tab\n"); printf("Hello There\\ -> backslash\n"); printf("Hello There\? -> question mark\n"); printf("Hello There\' -> single quote\n"); printf("Hello There\" -> double quote\n"); return(0); }
Results from running such code:
Hello There -> alert (bell) character Hello Ther -> backspace Hello There |-> formfeed Hello There |-> newline Hello There -> horizontal tab Hello There |-> vertical tab Hello There\ -> backslash Hello There? -> question mark Hello There' -> single quote Hello There" -> double quote
Was your hypothesis correct?
Yes, my hypothesis was correct.
Was your hypothesis not applicable?
My hypothesis was applicable, as shown above.
Is there more going on than you originally thought? (shortcomings in hypothesis)
The form-feed and the newline options produce the same result.
What shortcomings might there be in your experiment?
Not using all the escape sequences, for example \r (carriage return), this was not possible in my current experiment.
What shortcomings might there be in your data?
Not showing all the escape sequences shown in the table, as it was not possible in my current experiment.
What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.
Based on the data collected I can say that escape sequences can be very useful, if used correctly, if not your statement will look awful. Discoveries made are that \f (form feed) and \n (newline) are relatively the same thing, they produce the same output. Form feed is now an outdated command, so no need to worry about its usage.