So you want to modify some strings do you?
Well, first you have to understand what a string is...
Here is the dictionary definition:
In computer programming and some branches of mathematics , strings are sequences of various simple objects. These are selected from a predetermined set each entry of which is usually allocated a code. Most commonly these simple objects will be printable characters and the control codes that are used with them. The data types in which these are stored are also called strings and it is fairly common to use these types to store arbitrary variable length lumps of binary data. ...
This basically meand that it is a string of data, holding letters, as opposed to numbers. Think of it like this:
string[]="Hello World!"
this basically means that the variable string is an array which holds 12 pieces of data. Think of them like beads on a string:
-------H-e-l-l-o-_-W-o-r-l-d-!------------
Now is when it gets interesting. Say you wanted to make a program that added the text "There ain't no buttons to press so stop trying" when someone trys to press a button. You can't just say string[]=string[] + "message", you have to use special functions. Here is a list of all the functions with a description and usage;
FunctionsstrcpyUsage:
strcpy(destination variable, source variable)strcpy copies a string, including the null character terminator from the source string to the destination. This function returns a pointer to the destination string, or a NULL pointer on error.
strncpyUsage:
strncpy(destination variable, source variable, length) strncpy is similar to strcpy, but it allows the number of characters to be copied to be specified. If the source is shorter than the destination, than the destination is padded with null characters up to the length specified. This function returns a pointer to the destination string, or a NULL pointer on error.
strcatUsage:
strcat(string variable,"string to append")This function appends a source string to the end of a destination string. This function returns a pointer to the destination string, or a NULL pointer on error.
strcmpUsage:
strcmp(first string variable, second string variable)This function compares two strings. If the first string is greater than the second, it returns a number greater than zero. If the second string is greater, it returns a number less than zero. If the strings are equal, it returns 0.
strlenUsage:
strlen(string variable)This function returns the length of a string, not counting the null character at the end. That is, it returns the character count of the string, without the terminator.
memsetUsage:
memset(string variable,what to initialize all the "beads" with,length of the string aka how many beads it can hold)memset is useful to initialize a string to all nulls, or to any character. It sets the first N positions of the sting to the value passed. The destination may be specified by a pointer to any type, char, int, float, etc. A void pointer is used to allow different types to be specified. All arguments are necessary. It is customary when using this to have all the beads equal to NULL, or \0 (backslash zero). Use \0 only and never null. If you don't know how long the string will be, set it to something like 9999.
END OF FUNCTIONS
To use them in a file, you must include the file string.h by entering the following code at the top of the file:
#include <string.h>
I hope this has taught you something!
-Nathan