Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 04, 2012, 09:29:47 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Join our IRC channel: ##psp-programming on freenode
Home Help Search Shop Login Register
Digg This!
Poll
Question: Was this info helpful to you?  (Voting closed: April 19, 2006, 05:05:50 PM)
Yes - 12 (92.3%)
No (post why) - 1 (7.7%)
Total Voters: 13

Pages: [1]
Print
Author Topic: C:String Modification  (Read 3854 times)
nathan42100
Give miinaturvat Points!
Administrator
Hero Member
*

Karma: +32/-2
Offline Offline

Posts: 1161
934.18 points

View Inventory
Send Money to nathan42100


View Profile WWW
« on: April 19, 2006, 05:05:50 PM »

So you want to modify some strings do you?
Well, first you have to understand what a string is...
Here is the dictionary definition:
Quote from: "Wikipedia"
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;

Functions

strcpy
Usage: 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.

strncpy
Usage: 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.

strcat
Usage: 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.

strcmp
Usage: 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.

strlen
Usage: 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.

memset
Usage: 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
Logged

All of my work is released under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
dn ʎɐʍ sıɥʇ
Help support my computer projects!



Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #1 on: May 05, 2006, 07:02:18 AM »

You should format this into a tutorial, very nice.
Logged

Ravine
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 16
0.00 points

View Inventory
Send Money to Ravine

View Profile
« Reply #2 on: June 23, 2006, 10:52:35 AM »

Nevermind, fixed that problem, now have another.
Logged
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.291 seconds with 28 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com