Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[c++] How can I delete the last character in a char array?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Mon Jul 30, 2012 6:53 pm    Post subject: Reply with quote

blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
What would the difference be between a string and a char array?

String is like a sentence (Like "Fuck you")

Char array is a series of characters (Like "F", "u", "c", "k", " ", "y", "o", "u")

Char array = wastes less memory
String = more memory

yeah I know what a string is I was just wondering since "char"(characters obv.), characters would be what a string consisted of; letters, symbols, numbers.

I was just wondering why there was a difference like that.

A char can be anything, a symbol/letter/etc... The only real reason I see it's good for is saving very small amount of data (Like saving an item on a game, and the item has a number id which is converted to a char), or memory management.

If it's just a number ID why not just store it as an integer variable?

Memory management. char = 1 byte, int = 4 bytes (or something like that)

I really doubt a char is 1byte
Back to top
View user's profile Send private message MSN Messenger
Fafaffy
Cheater
Reputation: 65

Joined: 12 Dec 2007
Posts: 28

PostPosted: Mon Jul 30, 2012 6:54 pm    Post subject: Reply with quote

gogodr wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
What would the difference be between a string and a char array?

String is like a sentence (Like "Fuck you")

Char array is a series of characters (Like "F", "u", "c", "k", " ", "y", "o", "u")

Char array = wastes less memory
String = more memory

yeah I know what a string is I was just wondering since "char"(characters obv.), characters would be what a string consisted of; letters, symbols, numbers.

I was just wondering why there was a difference like that.

A char can be anything, a symbol/letter/etc... The only real reason I see it's good for is saving very small amount of data (Like saving an item on a game, and the item has a number id which is converted to a char), or memory management.

If it's just a number ID why not just store it as an integer variable?

Memory management. char = 1 byte, int = 4 bytes (or something like that)

I really doubt a char is 1byte

http://uk.answers.yahoo.com/question/index?qid=20081102023710AAZC6N3
Back to top
View user's profile Send private message Send e-mail
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Mon Jul 30, 2012 6:57 pm    Post subject: Reply with quote

oh wait
yeah you might be right, I was thinking in bits
Back to top
View user's profile Send private message MSN Messenger
bfsdbsdfbdsfb
Grandmaster Cheater
Reputation: 54

Joined: 06 Sep 2007
Posts: 702
Location: Oh noez.

PostPosted: Mon Jul 30, 2012 7:08 pm    Post subject: Reply with quote

blablfy. wrote:
gogodr wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
What would the difference be between a string and a char array?

String is like a sentence (Like "Fuck you")

Char array is a series of characters (Like "F", "u", "c", "k", " ", "y", "o", "u")

Char array = wastes less memory
String = more memory

yeah I know what a string is I was just wondering since "char"(characters obv.), characters would be what a string consisted of; letters, symbols, numbers.

I was just wondering why there was a difference like that.

A char can be anything, a symbol/letter/etc... The only real reason I see it's good for is saving very small amount of data (Like saving an item on a game, and the item has a number id which is converted to a char), or memory management.

If it's just a number ID why not just store it as an integer variable?

Memory management. char = 1 byte, int = 4 bytes (or something like that)

I really doubt a char is 1byte

http://uk.answers.yahoo.com/question/index?qid=20081102023710AAZC6N3

1bit = 0 or 1
2bits = 0, 1, 2 or 3
3 bits = 0, 1, 2, 3, 4, 5
so on so forth right?
So with 8 bits being 1 byte there would be stuff you couldn't store in char?

_________________
bsdfbdsfb
Back to top
View user's profile Send private message
Fafaffy
Cheater
Reputation: 65

Joined: 12 Dec 2007
Posts: 28

PostPosted: Mon Jul 30, 2012 7:15 pm    Post subject: Reply with quote

akaecius wrote:
blablfy. wrote:
gogodr wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
What would the difference be between a string and a char array?

String is like a sentence (Like "Fuck you")

Char array is a series of characters (Like "F", "u", "c", "k", " ", "y", "o", "u")

Char array = wastes less memory
String = more memory

yeah I know what a string is I was just wondering since "char"(characters obv.), characters would be what a string consisted of; letters, symbols, numbers.

I was just wondering why there was a difference like that.

A char can be anything, a symbol/letter/etc... The only real reason I see it's good for is saving very small amount of data (Like saving an item on a game, and the item has a number id which is converted to a char), or memory management.

If it's just a number ID why not just store it as an integer variable?

Memory management. char = 1 byte, int = 4 bytes (or something like that)

I really doubt a char is 1byte

http://uk.answers.yahoo.com/question/index?qid=20081102023710AAZC6N3

1bit = 0 or 1
2bits = 0, 1, 2 or 3
3 bits = 0, 1, 2, 3, 4, 5
so on so forth right?
So with 8 bits being 1 byte there would be stuff you couldn't store in char?

1 byte = 256 combinations

1 bit = 0 or 1
2 bits = 00, 01, 11, 10
etc...
Back to top
View user's profile Send private message Send e-mail
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Mon Jul 30, 2012 7:22 pm    Post subject: Reply with quote

akaecius wrote:
blablfy. wrote:
gogodr wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
What would the difference be between a string and a char array?

String is like a sentence (Like "Fuck you")

Char array is a series of characters (Like "F", "u", "c", "k", " ", "y", "o", "u")

Char array = wastes less memory
String = more memory

yeah I know what a string is I was just wondering since "char"(characters obv.), characters would be what a string consisted of; letters, symbols, numbers.

I was just wondering why there was a difference like that.

A char can be anything, a symbol/letter/etc... The only real reason I see it's good for is saving very small amount of data (Like saving an item on a game, and the item has a number id which is converted to a char), or memory management.

If it's just a number ID why not just store it as an integer variable?

Memory management. char = 1 byte, int = 4 bytes (or something like that)

I really doubt a char is 1byte

http://uk.answers.yahoo.com/question/index?qid=20081102023710AAZC6N3

1bit = 0 or 1
2bits = 0, 1, 2 or 3
3 bits = 0, 1, 2, 3, 4, 5
so on so forth right?
So with 8 bits being 1 byte there would be stuff you couldn't store in char?

1bit= 01
2bit = 0123
3bit = 01234567
4bit = 0123456789ABCDEF
you get the idea
Back to top
View user's profile Send private message MSN Messenger
Andyroo
Grandmaster Cheater
Reputation: 2

Joined: 04 Jul 2006
Posts: 964

PostPosted: Tue Jul 31, 2012 1:02 am    Post subject: Reply with quote

lets say you have a char array char temp[10]

then create a new char array, then copy the substr of temp into it.

char temp2[9]
strncpy(temp2, temp, 9);

make sure you use strncpy, or you'll try to copy a big array into a small array and get a compiler error.

if you want to make a dynamic char array, then you want to do

char *temp2 = new char[strlen(temp)];

and copy into that.

edit:
err you could just put a '\0' where the last char is too LOL looks like you solved it.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Tue Jul 31, 2012 11:40 am    Post subject: Reply with quote

putting null at the end of the array doesnt make it smaller though ...
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Aug 01, 2012 10:03 am    Post subject: Reply with quote

blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
blablfy. wrote:
akaecius wrote:
What would the difference be between a string and a char array?

String is like a sentence (Like "Fuck you")

Char array is a series of characters (Like "F", "u", "c", "k", " ", "y", "o", "u")

Char array = wastes less memory
String = more memory

yeah I know what a string is I was just wondering since "char"(characters obv.), characters would be what a string consisted of; letters, symbols, numbers.

I was just wondering why there was a difference like that.

A char can be anything, a symbol/letter/etc... The only real reason I see it's good for is saving very small amount of data (Like saving an item on a game, and the item has a number id which is converted to a char), or memory management.

If it's just a number ID why not just store it as an integer variable?

Memory management. char = 1 byte, int = 4 bytes (or something like that)

the size of an int is implementation defined. for more information on what the standard does define, see here

also with regards to size:

Code:
char[] str = "adsf";
char * str  = "asdf";


both require 5 bytes (4 bytes for characters + 1 byte for null terminator).

almost everything i've seen in this thread so far is wrong
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Aug 01, 2012 11:42 am    Post subject: Reply with quote

how is using malloc to reduce the size wrong?
Back to top
View user's profile Send private message MSN Messenger
Fafaffy
Cheater
Reputation: 65

Joined: 12 Dec 2007
Posts: 28

PostPosted: Wed Aug 01, 2012 12:42 pm    Post subject: Reply with quote

I'm horrible with C++ and stuff, so nothing I say you should trust Razz

What I was trying to imply was:

Instead of having a item id like this:
Code:

int item = 100;


You could store the item number as an ascii char

_________________
Brillia wrote:
I FUCKING FUCK SEX
Back to top
View user's profile Send private message Send e-mail
Andyroo
Grandmaster Cheater
Reputation: 2

Joined: 04 Jul 2006
Posts: 964

PostPosted: Wed Aug 01, 2012 2:21 pm    Post subject: Reply with quote

gogodr wrote:
putting null at the end of the array doesnt make it smaller though ...


he was asking how to delete the last character.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Aug 01, 2012 2:55 pm    Post subject: Reply with quote

Andyroo wrote:
gogodr wrote:
putting null at the end of the array doesnt make it smaller though ...


he was asking how to delete the last character.

my point is that he is not deleting it, he is replacing it
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites