HomeToolboxGallery

Software & Services
Hotels "R" MeIdleGuardKeyGuardNetflowNsUpkeeppsRadarVPN BypassWiFi Jitter Analyzer
Thronic.com content is FREE. Monetary support is optional.
Find anything of value?
PayPal, Bitcoin


Scripts
2D Rotation (JS)3D Rotation (JS)KiKiTrix (JS)AutoWrite (JS)Digitize Text (JS)Image Animation (JS)ASCII Loading Indicator (JS)Div Layer Movement (JS)Div Layer Resizing (JS)Text Scrolling (JS)Statistics Graph (PHP)RW Protect (BAT)SRT Renamer (PHP)String Encryption (PHP)Windows WiFi Hotspot (BAT)

General Computing

Thoughts on Coding StyleDomain 301 Perma RedirectWin/Linux PuTTY File TransferOpenVPN Site-to-Site SetupParity Data CheckingRclone Quick ReferenceSnapRAID NotesSSH TunnelingTransfer E-Mails with IMAPUDK Third Person CameraVPN Protocol Ports

GNU/Linux

Apache Process Mem UsageApache and CA OpenSSLApache2 htpasswd NotesCentOS 7 GlusterFS NotesCracking WEP and WPADebian 7 on Hyper-VDebian 7 to 8 UpgradeDebian 8 to 9 UpgradeDebian 9 DRBD SetupDebian and VirtualboxDebian and LSBInitScriptsDebian and systemdDebian Apache LetsEncryptDebian Apt AutoremoveDebian Cron & AnacronDebian KVM HypervisorLinux Bash ColorsLinux Cron BackupLinux Dnsmasq Setup NotesIptables Chain ExampleIptables Firewall and GatewayLinux MD RAID BasicsLinux iproute2 RoutingLinux SFTP Network ShareAvoid Linux Shell LoggingChecking Storage UsageLinux I/O Disk PerformanceLinux ZFS NotesVi/Vim Basic Reference

Microsoft
Bypass Windows PasswordDaz and ToolkitInt/Ext Drive ConfusionMRTG Network Traffic ViewMS Outlook NotesDOS File Content SearchDOS Merging VCF filesROBOCOPY Batch ScriptingPowerShell Reference NotesTeamViewer on HeadlessWorkgroup Failover ClusterDisable OneDrive in W10Windows WiFi and netshWindows Boot Custom UIHyper-V NetworkingHyper-V ReplicationIIS10 and PHP7 SetupPlex Media Server MigrationSecuring RDP ConnectionsServer 2012 R2 SetupWBAdmin Bare-Metal Backup

BSD/UNIX
FreeBSD 10.0 Setup (NOR)

C#/.NET
C# Associative ArraysC# Asynchronized WebcallC# Base64 GZipped JSONC# Code Execution TimerC# Dealing with WhitespacesC# djDBI for SQL CEC# Form ReferencingC# Get Folder SizeC# Handling DisconnectsC# HTTP POST and GETC# Importing DLL FunctionsC# Installing ServicesC# Kill and Start ProcessesC# Lambda ExpressionsC# Local AppData HandlingC# Memory StreamReadingC# Minimize to System TrayC# PDFsharp and MigraDocC# Public Fields vs PropsC# Registry HandlingC# Regular ExpressionsC# Require AdministratorC# RichTextBox File StreamC# Application SettingsC# SqlCeConnection CodeC# Start with hidden formC# String EncryptionC# Cross Thread HandlingC# Updating A RuntimeC# Gmail as SMTPVSI Dependency ErrorC# Handle XML

C/C++
C Autodelete Old FilesC/C++ Multiline StringsC Socket ListeningC StringsWin32 Button ControlWin32 Edit ControlWin32 GetLastError()Win32 KeyloggingWin32 KeypostingWin32 Simple WindowWin32 Socket ProgrammingWin32 VERSIONINFO

PHP
Bitwise IP HandlingPHP ClassesContent Length HandlingDetecting Mobile BrowsersdjDBI Database InterfaceHostname and Port RegexJSON Output HeadersMS Access Conn with COMProportional Image SizingRandom StringsRecursive FunctionsSending MailPHP SessionsSimple HTML-2-PDFPHP SimpleXMLTernary Operator and If/Else

SQL
MS Access Connection StringsMSSQL Case SensitivityMySQL Root Password ResetMySQL Check Slow QueriesColumn CountingQuick Note on CROSS JOINQuick Note on INNER JOINRandom Rows

HTML
HTML Raw Skeleton

JavaScript
AJAX Basicsevent.keyCode ReferenceIE7 Onclick EventsIE GIF Animation Problem

Java
Java Notater (NOR)

CSS
Border StylesFlyout MenusFont-Family Reference

Electrical

Betegnelser og SpenningsfallLovdata Elektrisk ArbeidResistors Series and ParallelSilicone and Circuit Boards

RC Hobby
Engine Break-In Procedure

Gaming

CSS Dedicated Server






Dag J Nedrelid
System and web developer. Tech hobbyist. Dad. Gamer.

C Strings

By Dag, on December 30th, 2016

My notes about using C-type strings.

Static Character Arrays
/* 
 * The most common way of creating a string. This declaration will create a 
 * static sized buffer that may contain up to 50 characters, but not more. 
 */

// Declaration
char szString[50];

// Initialization
/*
 * This initialization will fill the array with nulls. This is only necessary 
 * if the array will be fed a string without a null character. A null character 
 * (or null terminator) is just an escaped zero '\0'. A char array does by 
 * default contain garbage data, which will be printed with the string unless 
 * it's null terminated.
 */
memset(szString, 0, sizeof(szString));

String Literals / String Constants
/* 
 * Another common way of creating a string. This one is static, and cannot 
 * be changed. The program will create this string somewhere in read-only 
 * memory, and only give the starting address to the pointer variable. The 
 * string will automatically be created with a null character at the end. 
 * The pointer can be given a new string at any time, but the old one will 
 * keep floating around in memory, and a dynamicly sized array (malloc) or 
 * a static char array will be best suited for strings that will change a 
 * lot.
 */

// Declaration and initialization
char* szString[] = "This is a string literal. "
                   "Also known as a string constant.";

/*
 * This way of creating a string is good for when it's needed to create a 
 * constant string that's not going to change, like a #define, only being 
 * able to create it later during the program life span, conditionally.
 */

Dynamic Character Arrays
/* 
 * Just like static character arrays, only with dynamic sizes. Good for 
 * perfectionists that don't want to waste a single byte! The array will 
 * be declared with the function malloc(), and can be freed with free().
 * Then it can be declared again, with a new size.
 */

// Declaration
char *szString;
szString = (char *)malloc(50 * sizeof(char));

// Initialization
memset(szString, 0, sizeof(szString));

// Applying a string, that you can manage like with a normal array.
strcpy(szString, "Hello world."); // Careful with buffer overruns.

// Replacing the period.
szString[11] = '!';

// Freeing memory and pointer for new use.
free(szString);


©2007-2018 https://thronic.com
Π