Compare commits
2 Commits
79415e38db
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 67b7ced5ba | |||
| bdde9bd1ca |
Executable
BIN
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *src = fopen(argv[1], "rb");
|
||||
FILE *dst = fopen(argv[2], "wb");
|
||||
|
||||
BYTE b;
|
||||
|
||||
while (fread(&b, sizeof(b), 1, src) != 0)
|
||||
{
|
||||
fwrite(&b, sizeof(b), 1, dst);
|
||||
}
|
||||
|
||||
fclose(dst);
|
||||
fclose(src);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Hayet, 77666327
|
||||
Munna, 59950786
|
||||
|
Executable
BIN
Binary file not shown.
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <cs50.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct node
|
||||
{
|
||||
int number;
|
||||
struct node *next;
|
||||
} node;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
node *list = NULL;
|
||||
// Create list
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int x = get_int("Number: ");
|
||||
|
||||
node *n = malloc(sizeof(node));
|
||||
|
||||
if (n == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
n->number = x;
|
||||
n->next = list;
|
||||
|
||||
list = n;
|
||||
}
|
||||
|
||||
|
||||
// Print list
|
||||
node *ptr = list;
|
||||
|
||||
while (ptr != NULL)
|
||||
{
|
||||
printf("%i\n", ptr->number);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
|
||||
// Free memory
|
||||
ptr = list;
|
||||
|
||||
while (ptr != NULL)
|
||||
{
|
||||
node *tmp = ptr;
|
||||
ptr = ptr->next;
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <cs50.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct node
|
||||
{
|
||||
int number;
|
||||
struct node *next;
|
||||
} node;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
node *list = NULL;
|
||||
// Create List
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int x = get_int("Number: ");
|
||||
|
||||
node *n = malloc(sizeof(node));
|
||||
n->number = x;
|
||||
n->next = list;
|
||||
|
||||
list = n;
|
||||
|
||||
if (n == NULL)
|
||||
{
|
||||
printf("Malloc failed. \n");
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
for (node *ptr = list; ptr !=NULL; ptr = ptr->next)
|
||||
{
|
||||
printf("%i\n", ptr->number);
|
||||
}
|
||||
|
||||
node *ptr = list;
|
||||
while(ptr !=NULL)
|
||||
{
|
||||
node *tmp = ptr;
|
||||
ptr = ptr->next;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// FILE here calls FILE function from stdio.h & "a" using for apend.
|
||||
FILE *file = fopen("phonebook.csv", "a");
|
||||
if (file == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
char *name = get_string("Name: ");
|
||||
char *number = get_string("Number: ");
|
||||
|
||||
fprintf(file, "%s, %s\n", name, number);
|
||||
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Hayet, 77666327
|
||||
Munna, 59950786
|
||||
|
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
s = input("Do you agree? ")
|
||||
s = s.lower()
|
||||
|
||||
if s in ["y", "yes"]:
|
||||
|
||||
print("Agreed.")
|
||||
|
||||
else:
|
||||
print("Not Agreed.")
|
||||
@@ -0,0 +1,5 @@
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
before = Image.open("bridge.bmp")
|
||||
after = before.filter(ImageFilter.BoxBlur(10))
|
||||
after.safe("out.bmp")
|
||||
@@ -0,0 +1,3 @@
|
||||
for _ i in range(3):
|
||||
print("Meow")
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
s = input("s: ")
|
||||
t = input ("t: ")
|
||||
|
||||
if s == t:
|
||||
print("Same")
|
||||
else:
|
||||
print("Different")
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
s = input("s: ")
|
||||
|
||||
t = s.capitalize()
|
||||
|
||||
print(f"s: {s}")
|
||||
print(f"t: {t}")
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
words = set()
|
||||
|
||||
def check(word):
|
||||
return word.lower() in words
|
||||
|
||||
def load(dictionary):
|
||||
with open(dictionary) as file:
|
||||
words.update(file.read().splitlines())
|
||||
return True
|
||||
|
||||
def size():
|
||||
return len(words)
|
||||
|
||||
def unload():
|
||||
return True
|
||||
@@ -0,0 +1 @@
|
||||
print ("Hello World")
|
||||
@@ -0,0 +1,12 @@
|
||||
while True:
|
||||
n = int(input("Height: "))
|
||||
if n > 0:
|
||||
break
|
||||
|
||||
for i in range(n):
|
||||
print("#")
|
||||
|
||||
|
||||
for i in range(4):
|
||||
print("?", end ="")
|
||||
print()
|
||||
@@ -0,0 +1,6 @@
|
||||
before = input("Before: ")
|
||||
print("After: ", end="")
|
||||
for c in before:
|
||||
print(c.upper(), end="")
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
|
||||
{
|
||||
int n = 50;
|
||||
int *p = &n;
|
||||
printf("%p\n", p);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const iunt capacity = 50;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
person people[CAPACITY]
|
||||
int size;
|
||||
} stack;
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int scores[1024];
|
||||
for (int i =0; i < 1024; i++)
|
||||
{
|
||||
printf("%i\n", scores[i]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int hash(char *word);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *word= get_string("Word: ");
|
||||
printf("Hash value: %i\n", hash(word));
|
||||
}
|
||||
|
||||
int hash(char *word)
|
||||
{
|
||||
if (word == NULL || strlen(word) == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
char c = word[0];
|
||||
if (isalpha(c))
|
||||
{
|
||||
c = toupper(c);
|
||||
return c -'A';
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Submodule
+1
Submodule isiah/learning-area added at 31b3ff0a62
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int *list = malloc(3 * sizeof(int));
|
||||
if(list ==NULL)
|
||||
|
||||
list[0] = 1;
|
||||
list[1] = 2;
|
||||
list[2] = 3;
|
||||
|
||||
// Time passes
|
||||
|
||||
int *tmp = realloc(list, 4 * sizeof(int));
|
||||
|
||||
if (tmp == NULL)
|
||||
{
|
||||
free(list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Copy old list into new list
|
||||
for (int i = 0; i <3; i++)
|
||||
{
|
||||
tmp[i] = list[i];
|
||||
}
|
||||
tmp[3] = 4;
|
||||
|
||||
// Free original list
|
||||
free(list);
|
||||
|
||||
list = tmp;
|
||||
|
||||
for (int i = 0; i <3; i++)
|
||||
{
|
||||
printf("%i\n", list[i]);
|
||||
}
|
||||
free(list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct node
|
||||
{
|
||||
int number;
|
||||
struct node *next;
|
||||
} node;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
node *list = NULL;
|
||||
|
||||
for (int = 0; i < 3; i++)
|
||||
{
|
||||
node *n = malloc(sizeof(node));
|
||||
if (n == NULL)
|
||||
{return 1;}
|
||||
// n-> = NULL;
|
||||
(*n).number = get_int("Number: ");
|
||||
// n-> = NULL;
|
||||
(*)n.next = NULL;
|
||||
|
||||
// Prepend node to list
|
||||
n->next = list
|
||||
list =n;
|
||||
}
|
||||
|
||||
// Print Numbers
|
||||
node *ptr = list;
|
||||
while (ptr !=NULL)
|
||||
{
|
||||
printf("%i\n", ptr->number);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Demonstrates memory error via valgrind
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int *x = malloc(3 * sizeof(int));
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
x[0] = 72;
|
||||
x[1] = 73;
|
||||
x[2] = 33;
|
||||
free(x);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user