-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d6428a
commit 06b5b8f
Showing
4 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: atoi | ||
desc: Implement the C stdlib function atoi | ||
class: COMP1511 | ||
difficulty: 2 | ||
--- | ||
|
||
# atoi | ||
|
||
Your task is to implement the C Standard Library function `atoi`. `atoi` takes in a `const char *` that is guaranteed to be a numerical string, e.g. `"123"`, and returns the numerical form of that string. | ||
|
||
For example, | ||
|
||
``` | ||
atoi("123") -> 123 | ||
atoi("19") -> 19 | ||
``` | ||
|
||
Your function should take in command line arguments (which are guaranteed to be numerical), and use your implementation of `atoi` to convert them into a number, and print it out. | ||
|
||
Furthermore, once you have printed out all the command line arguments, you should print out the sum and product of all these arguments. | ||
|
||
The output from your program should look **exactly** like this: | ||
|
||
```bash:~/1511-revision/atoi | ||
$ dcc atoi.c -o atoi | ||
$ ./atoi 3 2 | ||
3 | ||
2 | ||
5 6 | ||
``` | ||
|
||
## Assumptions/Restrictions/Clarifications | ||
|
||
It is guaranteed that the command lines argument given in the autotest are numerical. | ||
|
||
You should not use the library implementation of `atoi` as that defeats the whole purpose of this exercise. | ||
|
||
## CSE Autotest | ||
|
||
When you think your program is working, you can use CSE autotest to test your solution. | ||
|
||
```bash:~/1511-revision/atoi | ||
$ 1511 csesoc-autotest atoi | ||
``` | ||
|
||
## Solution | ||
|
||
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/atoi/solution.c). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: strcmp | ||
desc: Implement the C stdlib function strcmp | ||
class: COMP1511 | ||
difficulty: 2 | ||
--- | ||
|
||
# strcmp | ||
|
||
Your task is to implement the C Standard Library function `strcmp`. `strcmp` takes in two `const char *` and returns an integer depending on the differences between the two strings. | ||
|
||
`strcmp` works by sequentially going through both strings and comparing each character. | ||
If `char 1` < `char 2`, then we would return `-1`. | ||
If `char 1 > char 2`, then we would return `1`. | ||
|
||
However, If both strings equal each other, then we would return `0`. | ||
|
||
For example, | ||
|
||
``` | ||
strcmp("hi", "hi") -> 0 | ||
strcmp("a", "b") -> -1 | ||
``` | ||
|
||
The output from your program should look **exactly** like this: | ||
|
||
```bash:~/1511-revision/strcmp | ||
$ dcc strcmp.c -o strcmp | ||
$ ./strcmp "hello" "hello" | ||
0 | ||
``` | ||
|
||
## Assumptions/Restrictions/Clarifications | ||
|
||
You should not use the library implementation of `strcmp` as that defeats the whole purpose of this exercise. | ||
|
||
It is guaranteed that your function is only expected to return `0`, `1`, and `-1`. | ||
|
||
## CSE Autotest | ||
|
||
When you think your program is working, you can use CSE autotest to test your solution. | ||
|
||
```bash:~/1511-revision/strcmp | ||
$ 1511 csesoc-autotest strcmp | ||
``` | ||
|
||
## Solution | ||
|
||
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/strcmp/solution.c). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: strlen | ||
desc: Implement the C stdlib function strlen | ||
class: COMP1511 | ||
difficulty: 2 | ||
--- | ||
|
||
# strlen | ||
|
||
Your task is to implement the C Standard Library function `strlen`. `strlen` takes in a `const char *` and returns an integer that is the length of the given string, | ||
|
||
```` | ||
The output from your program should look **exactly** like this: | ||
```bash:~/1511-revision/strlen | ||
$ dcc strlen -o strlen | ||
$ ./strlen "hi" | ||
2 | ||
```` | ||
|
||
## Assumptions/Restrictions/Clarifications | ||
|
||
You should not use the library implementation of `strlen` as that defeats the whole purpose of this exercise. | ||
|
||
Note that `strlen` does not count the null terminator `\0` as part of a string's length. | ||
|
||
## CSE Autotest | ||
|
||
When you think your program is working, you can use CSE autotest to test your solution. | ||
|
||
```bash:~/1511-revision/strlen | ||
$ 1511 csesoc-autotest strlen | ||
``` | ||
|
||
## Solution | ||
|
||
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/strlen/solution.c). |