first commit
This commit is contained in:
commit
966c679efb
10 changed files with 565 additions and 0 deletions
273
.gitignore
vendored
Normal file
273
.gitignore
vendored
Normal file
|
@ -0,0 +1,273 @@
|
|||
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,c,c++,cmake,linux,qt,qtcreator,windows
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,c,c++,cmake,linux,qt,qtcreator,windows
|
||||
|
||||
### C ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
### C++ ###
|
||||
# Prerequisites
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
|
||||
# Precompiled Headers
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
|
||||
# Executables
|
||||
|
||||
### CMake ###
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### macOS Patch ###
|
||||
# iCloud generated files
|
||||
*.icloud
|
||||
|
||||
### Qt ###
|
||||
# C++ objects and libs
|
||||
|
||||
# Qt-es
|
||||
object_script.*.Release
|
||||
object_script.*.Debug
|
||||
*_plugin_import.cpp
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
*.pro.user
|
||||
*.pro.user.*
|
||||
*.qbs.user
|
||||
*.qbs.user.*
|
||||
*.moc
|
||||
moc_*.cpp
|
||||
moc_*.h
|
||||
qrc_*.cpp
|
||||
ui_*.h
|
||||
*.qmlc
|
||||
*.jsc
|
||||
Makefile*
|
||||
*build-*
|
||||
*.qm
|
||||
*.prl
|
||||
|
||||
# Qt unit tests
|
||||
target_wrapper.*
|
||||
|
||||
# QtCreator
|
||||
*.autosave
|
||||
|
||||
# QtCreator Qml
|
||||
*.qmlproject.user
|
||||
*.qmlproject.user.*
|
||||
|
||||
# QtCreator CMake
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# QtCreator 4.8< compilation database
|
||||
|
||||
# QtCreator local machine specific files for imported projects
|
||||
*creator.user*
|
||||
|
||||
*_qmlcache.qrc
|
||||
|
||||
### QtCreator ###
|
||||
# gitignore for Qt Creator like IDE for pure C/C++ project without Qt
|
||||
#
|
||||
# Reference: http://doc.qt.io/qtcreator/creator-project-generic.html
|
||||
|
||||
|
||||
|
||||
# Qt Creator autogenerated files
|
||||
|
||||
|
||||
# A listing of all the files included in the project
|
||||
*.files
|
||||
|
||||
# Include directories
|
||||
*.includes
|
||||
|
||||
# Project configuration settings like predefined Macros
|
||||
*.config
|
||||
|
||||
# Qt Creator settings
|
||||
*.creator
|
||||
|
||||
# User project settings
|
||||
*.creator.user*
|
||||
|
||||
# Qt Creator backups
|
||||
|
||||
# Flags for Clang Code Model
|
||||
*.cxxflags
|
||||
*.cflags
|
||||
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
# Support for Project snippet scope
|
||||
.vscode/*.code-snippets
|
||||
|
||||
# Ignore code-workspaces
|
||||
*.code-workspace
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,c,c++,cmake,linux,qt,qtcreator,windows
|
||||
|
||||
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
|
||||
|
29
LICENSE
Normal file
29
LICENSE
Normal file
|
@ -0,0 +1,29 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2022, Tony Bark
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
7
README.md
Normal file
7
README.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# C Practice
|
||||
|
||||
This is some really *old* C code that I wrote with a friend when I was still figuring what programming language best suited me. I'm providing this as is for the sake archiving.
|
||||
|
||||
## License
|
||||
|
||||
This archive is dual-licensed under the [BSD-3-Clause](COPYING) or the [UNLICENSE](UNLICENSE).
|
24
UNLICENSE
Normal file
24
UNLICENSE
Normal file
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
12
hello-world-qt.c
Normal file
12
hello-world-qt.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <QtGui>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
QLabel label("Hello, world!");
|
||||
label.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
12
hello-world.c
Normal file
12
hello-world.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char initial;
|
||||
|
||||
printf("Please enter the following info:");
|
||||
scanf("%c", &initial); // scanf("Initial i%". i%)
|
||||
print("Your initials are %i");
|
||||
|
||||
return 0;
|
||||
}
|
144
nightwish/pointers-rewrite.c
Normal file
144
nightwish/pointers-rewrite.c
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
|
||||
Here, i will attempt to show you some simple concepts of 'pointers'
|
||||
Including a few common uses, as well as the differences
|
||||
between a dereference and a reference pass...
|
||||
|
||||
*/
|
||||
|
||||
/* standard include file for IO.... */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/* Main function */
|
||||
|
||||
int main ( int argc, char * argv[] )
|
||||
|
||||
/*
|
||||
The above is a stack pointer, it's placed on the current
|
||||
execution space of the program (the memory is allocated at startup).
|
||||
There's no heap used here and thus we don't 'free' any memory.
|
||||
argv[] is a string constant,
|
||||
it's the command line passed to the program
|
||||
on startup. Where [0] is the actual executable name
|
||||
*/
|
||||
|
||||
{
|
||||
|
||||
/* Now, let's make a pointer! */
|
||||
|
||||
char *FirstPointer; /* This is a 'stack pointer' */
|
||||
|
||||
/*
|
||||
|
||||
Remember that the above IS a pointer, but it's an stack-space
|
||||
one. Meaning it's allocated at startup.
|
||||
|
||||
The stack can only be a certian size, if all the data
|
||||
won't fit on it, it may get cut off or give
|
||||
undefined behaviour. So let's convert our 'stack' to a
|
||||
'heap pointer below
|
||||
*/
|
||||
|
||||
FirstPointer = (char *) malloc(sizeof(char) * 200000);
|
||||
|
||||
/*
|
||||
OK! Now we have a nice, BIG space in the 'heap' (the rest of the
|
||||
system's RAM that's not beeing used by a program). We'll just
|
||||
work with data under 200000 bytes long for now so as not to cause
|
||||
a memory leak. So, what shal we -do- with our baby? Hmm, i have
|
||||
an idea.....
|
||||
*/
|
||||
|
||||
*FirstPointer = (char *)"Hello There, i belong on the heap!\n";
|
||||
|
||||
/* Let's make it say something for us!
|
||||
The trick here is the asterisk (*) will 'dereference' the pointer.
|
||||
When we dereference a pointer, we no longer worry about the
|
||||
memory address, we worry about, and work with the DATA!
|
||||
If we work by REFERENCE we are working with the ADDRESS!
|
||||
The &-sign is the reference operator, we'll work with that soon.
|
||||
*/
|
||||
|
||||
/* Let's put something on screen... */
|
||||
|
||||
printf("%s", FirstPointer);
|
||||
|
||||
/* Ok, we have text-on-screen action! Sexy! Now, let's make another
|
||||
pointer, here's where reference play comes in!
|
||||
*/
|
||||
|
||||
char *SecondPointer; /* Another char (byte) pointer, to match types with the first one. */
|
||||
|
||||
/* Now let's see what happens if we do the following.... */
|
||||
|
||||
SecondPointer = (char *)&FirstPointer;
|
||||
|
||||
/* We passed the ADDRESS of the 'FirstPointer' (our heap pointer)
|
||||
to our second, which can accept the address, let's print the
|
||||
second one to the screen!
|
||||
*/
|
||||
|
||||
printf("%s", SecondPointer);
|
||||
|
||||
/* Sweet, more screen action! Now let's do something a bit odd....
|
||||
*/
|
||||
|
||||
char *ThirdPointer; /* Wow this crap is becomming common.... */
|
||||
|
||||
ThirdPointer = (char *) *SecondPointer;
|
||||
|
||||
/* Hmm, interesting... We have just copied the data from the FIRST
|
||||
pointer to the third! But how???
|
||||
|
||||
It's simple, when we did the address assign (&FirstPointer)
|
||||
earlier in the code, it placed the address in SecondPointer.
|
||||
That links SecondPointer and FirstPointer together! They can share
|
||||
data now. ThirdPointer now equals the data of second pointer,
|
||||
which by address points to first pointer, so we have a circle.
|
||||
|
||||
Let's see it in action.....
|
||||
*/
|
||||
|
||||
printf("%s", ThirdPointer);
|
||||
|
||||
/* Yay, more output, But what happens if we do something like this?
|
||||
*/
|
||||
|
||||
printf("%s %s %s", &FirstPointer, &SecondPointer, &ThirdPointer);
|
||||
|
||||
/* Well, what'cha know? We have the addresses on screen of all
|
||||
three pointers! Two of them (first and second) should be the same
|
||||
While third should be different.....
|
||||
|
||||
Reason for third beeing different???
|
||||
|
||||
We didn't assign it ANY Address, ONLY data!
|
||||
|
||||
Ok, we have worked with our pointers and are all done....
|
||||
What do we do now? THat funny malloc() stuff did something
|
||||
right? Yes it did! It told the kernel of the OS to allocate
|
||||
some of the computer's RAM so we could put stuff in it.
|
||||
Now we need to be nice to the OS and our computer and
|
||||
give the RAM back with free(). Free() tells the kernel
|
||||
'We're done, you can have this back now'. If a program with an
|
||||
malloc() ends without a free() to release, you have a memory leak.
|
||||
|
||||
A memory leak is when RAM is allocated and not freed once the
|
||||
stack is destroyed (main returns and exits). The RAM is still
|
||||
there and possibly usable, but it hasn't been set back to
|
||||
zero-byte yet. So to be nice let's free......
|
||||
*/
|
||||
|
||||
free(FirstPointer); /* Done, no mem leaks now! */
|
||||
|
||||
/* And a nice return to let the kernel know we're all done */
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
34
nightwish/printself.c
Normal file
34
nightwish/printself.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main( void )
|
||||
{
|
||||
|
||||
FILE *source;
|
||||
|
||||
source = fopen("printself.c", "r");
|
||||
|
||||
long file_size;
|
||||
|
||||
fseek(source, 0, SEEK_END);
|
||||
|
||||
file_size = ftell(source);
|
||||
|
||||
rewind(source);
|
||||
|
||||
char *filedata;
|
||||
|
||||
filedata = (char*) malloc(sizeof(char) * file_size);
|
||||
|
||||
fread(filedata, 1, file_size, source);
|
||||
|
||||
fclose(source);
|
||||
|
||||
printf("%s\n", filedata);
|
||||
|
||||
free(filedata);
|
||||
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
16
nightwish/recurse.c
Normal file
16
nightwish/recurse.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void Recurse( int number )
|
||||
{
|
||||
|
||||
printf("Call #: %d\n", number);
|
||||
Recurse(number+1);
|
||||
}
|
||||
|
||||
int main( void )
|
||||
{
|
||||
|
||||
Recurse(1);
|
||||
|
||||
return 0;
|
||||
}
|
14
tax-owe-app-hw.c
Normal file
14
tax-owe-app-hw.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// This application is purely for study purposes.
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char name[100];
|
||||
|
||||
printf("Tell me your name.\n");
|
||||
scanf("%s", name);
|
||||
printf("Welcome, %s!\n", name);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in a new issue