user name | @ | device name | : | file system location | $ |
---|---|---|---|---|---|
user | @ | DESKTOP-THMS2PJ | : | ~ | $ |
user@DESKTOP-THMS2PJ:~$ mkdir dev
user@DESKTOP-THMS2PJ:~$ cd dev
user@DESKTOP-THMS2PJ:~/dev$ cd /
user@DESKTOP-THMS2PJ:/$ cd /home/user/dev/
user@DESKTOP-THMS2PJ:~/dev$ pwd
/home/user/dev
user@DESKTOP-THMS2PJ:~/dev$ cd ..
user@DESKTOP-THMS2PJ:~$
Command | Action |
---|---|
gcc |
Given an input .c file, compile the code. |
python3 |
Open the python3 interpreter. Given an input .py file, run that script. |
echo |
Given an input string, print that string. Can be used to write text into a file. |
cat |
Given an input file name, print the contents of that file. For "concatenate" - historically used to join multiple files together, but may be used on a single file. |
cd |
Change directory. If given no argument, return to ~. |
pwd |
Print working directory. Prints the full name of the current location in the file system. |
ls |
List. Lists all files and sub-directories in the current directory. |
Once you commit a trivial change to this README, you have complete git setup.
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$ gcc x_sort.c
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$ ./a.out
hello
Keep it up!
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$ touch test.c
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$ nano test.c
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$ code .
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/hw0$
// This test.c, a file for testing C. (or another description)
#include <stdio.h>
int main()
{
printf("test\n") ;
return 0 ;
}
int x = 0, y = 0, z = 0 ;
x = 10 ;
// x = 20 ;
printf("%d", x) ; // Prints "10"
y = 20 ;
/*
z = x * y ;
x = x * z ;
y = y * z ;
*/
printf("%d", y) ; // Prints "20"
It is good practice to end every line of code you write with a "//" comment until you write code with no bugs on the first try at P > .5.
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ gcc test.c
test.c: In function ‘main’:
test.c:6:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
6 | printf("test\n") ;
| ^~~~~~
test.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
+++ |+#include <stdio.h>
1 | // This test.c, a file for testing C. (or another description)
test.c:6:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
6 | printf("test\n") ;
| ^~~~~~
test.c:6:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
I will receive an alarming number of Discord messages containing warnings similar to this one. That is okay, but...
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ gcc test.c
test.c: In function ‘main’:
test.c:6:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
6 | printf("test\n") ;
| ^~~~~~
test.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
+++ |+#include <stdio.h>
1 | // This test.c, a file for testing C. (or another description)
test.c:6:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
6 | printf("test\n") ;
| ^~~~~~
test.c:6:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
gcc explicitly tells you what code to write and where. It is helping you!
test.c:6:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
6 | printf("test\n") ;
| ^~~~~~
test.c:6:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
6 | printf("test\n") ;
| ^~~~~~
// This test.c, a file for testing C. (or another description)
#include <stdio.h> // for printf
int main()
{
printf("test\n") ;
return 0 ;
}
main()
// This test.c, a file for testing C. (or another description)
#include <stdio.h> // for printf
int notmain()
{
printf("test\n") ;
return 0 ;
}
main()
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ gcc test.c
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ ls
test.c
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
main()
#include <stdio.h> // for printf
printf("test\n") ;
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ gcc test.c
test.c:3:8: error: expected declaration specifiers or ‘...’ before string constant
3 | printf("test\n") ;
| ^~~~~~~~
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
int main()
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ echo "int main() {return 0;}" >test.c && gcc test.c && ./a.out
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ echo "void main() {return;}" >test.c && gcc test.c && ./a.out
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ echo "char *main() {return \"hi\";}" >test.c && gcc test.c && ./a.out
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ echo "string main() {return 0;}" >test.c && gcc test.c && ./a.out
test.c:1:1: error: unknown type name ‘string’
1 | string main() {return 0;}
| ^~~~~~
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
int main()
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ echo "int main() {return 0;}" >test.c && g++ test.c && ./a.out
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ echo "void main() {return;}" >test.c && g++ test.c && ./a.out
test.c:1:1: error: ‘::main’ must return ‘int’
1 | void main() {return;}
| ^~~~
test.c: In function ‘int main()’:
test.c:1:14: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
1 | void main() {return;}
| ^~~~~~
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
return 0 ;
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ gcc test.c
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
exit(1) ;
#include <stdio.h> // for printf
#include <stdlib.h> // for exit
int main()
{
if (0)
{
exit(1) ;
}
printf("test\n") ;
return 0 ;
}
// This test.c, a file for testing C. (or another description)
#include <stdio.h> // for printf
int main()
{
printf("test\n") ;
return 0 ;
}
txt = "For only {price:.2f} dollars!"
print(txt.format(price = 49))
>>> txt = "hello there"
>>> print(txt.format())
hello there
>>> print("hello there".format())
hello there
>>>
#include <stdio.h> // for printf
int main()
{
int rval = 0 ; // for "return value"
printf("rval = %d\n", rval) ;
return rval ;
}
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$ gcc test.c && ./a.out
rval = 0
user@DESKTOP-THMS2PJ:~/dev/as_zagreb/271sp24/notes$
// This test.c, a file for testing C. (or another description)
#include <stdio.h> // for printf
int main()
{
printf("test\n") ;
return 0 ;
}