Skip to content
Permalink
Browse files
Finished the c course
  • Loading branch information
Oliver committed Dec 16, 2020
1 parent 8fc19e1 commit 48105cbedbbd2de5b977a799d84379c1b8d27980
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 4 deletions.
@@ -0,0 +1 @@
Hello Oliver, It's good to finish this 4 hour video.
106 C Project/Project_C/main.c 100755 → 100644
@@ -18,9 +18,7 @@ struct Student{

int main()
{
/*
//Data Types
//Numbers
int age = 10;
double gpa = 3.7;
@@ -35,6 +33,7 @@ int main()
//%f = Floating Points
//%s = Strings/Letters
//%c = Single Character
//%p = Pointer / Address
printf("My favourite %s is %d and %f and a single character %c\n", "number", 700, 700.5, 'i');

//F-Type Strings / Functions
@@ -139,11 +138,110 @@ int main()
printf("Name: %s\nMajor: %s\nAge: %d\nGPA: %f\n", oliver.name, oliver.major, oliver.age, oliver.gpa);
printf("\n");
printf("Name: %s\nMajor: %s\nAge: %d\nGPA: %f\n", james.name, james.major, james.age, james.gpa);
*/

//While Loops
int index = 1;
while(index <= 5){
printf("%d\n", index);
//index = index + 1;
index++;
}

//Do-While Loops
int index2 = 6;
do {
printf("%d\n", index2);
//index2 = index2 + 1;
index2++;
} while(index2 <= 5);

//Guessing Game
int secretNumber = 5;
int guess;
int guessCount = 0;
int guessLimit = 3;
int outOfGuesses = 0;

while(guess != secretNumber && outOfGuesses == 0){
if(guessCount < guessLimit){
printf("Enter a number: ");
scanf("%d", &guess);
guessCount++;
} else{
outOfGuesses = 1;
}
}
if(outOfGuesses == 1){
printf("Out of guesses!");
}else{
printf("You won!");
}

//For Loops, Could be; -- would be going backwards, i = i + 2 would add 2 everytime.
int i;
for(i = 1; i <= 5; i++){
printf("%d\n", i);
}

int l;
int commands[] = {23,54,76,44,25,48,23,53,64,23,66,};
for(l = 0; l < 6; l++){
printf("%d\n", commands[l]);
}

//2D Arrays & Nested Loops
int nums[3][2] = {
{1,2},
{3,4},
{5,6}
};
//printf("%d\n", nums[0][1]);
//printf("%d\n", nums[2][1]);

int i, j;
for(i = 0; i < 3; i++){
for(j = 0; j < 2; j++){
printf("%d,", nums[i][j]);
}
printf("\n");
}

//Memory Addresses
int age = 30;
double gpa = 3.4;
char grade = 'A';

printf("age : %p\ngpa : %p\ngrade : %p\n", &age, &gpa, &grade);

//Pointers
int age = 30;
int * pAge = &age;
double gpa = 3.5;
double * pGpa = &gpa;
char grade = 'A';
char * pGrade = &grade;
printf("Age's memmory register: %p\n", &age);

//Dereferencing Pointers
int dage = 30;
int *pDage = &dage;

printf("%d", *&pDage);

//Writing to a file.
//FILE * fpointer = fopen("employees.txt", "w");
//fprintf(fpointer, "Hello Oliver, It's good to finish this 4 hour video.");
//fclose(fpointer);

//Writing to a file.
char line[255];
FILE * fpointer = fopen("employees.txt", "r");
fgets(line, 255, fpointer);
printf("%s", line);
fclose(fpointer);
}


//Functions
void sayHi(){
printf("Hellow World!\n");
@@ -205,4 +303,4 @@ void test(){
printf("Invalid Grade!");
}

}
}

0 comments on commit 48105cb

Please sign in to comment.