🔒 Locked
Strings and Such
Advertisement
Original Post
Is there any algorithm to convert a char str[255] to a char *str?
And Vice versa? If so please, do tell.
Actually, a char[255] is a char*, but the reverse isn''t true - yet. To make a char* a char[n] where n is a constant integer, you need to allocate a region of memory using one of the alloc functions (in C) or new in C++. When you''re done you''ll need to deallocate that memory using free in C or delete in C++.
Ok, *cough*. How exactly is that done?
I''m not using C, im using C++. Can I get an example of how to use "new" and "delete" to make a char *str a char[n]? I''d be a huge help.
char* c;
int n = 10;
c = new char[n];
// c is now char c[10];
// done with c?
delete c;
Since this is basic C++, I''d ask you to go read up on the language. This forum is not a tutorial ground to provide all solutions; it is to point you in the right direction to find solutions for yourself.
Thank ya. And yes, this post probably should have been on another board, but thanks for answering anyway.
No problem.
I''m not saying don''t post questions like this here; I''m saying that we''re here to think through the problem with you. Please post, because that''s what makes these forums worthwhile - the prospect of learning from the questions of others (sorta like a classroom). I''m just saying that once you''ve been pointed in the right direction, you owe it to the forum - the "class" - to do some homework yourself and then come back with your results. That way, everybody learns faster.
Anyway, I''m glad your problem is solved and hopefully you''ve also gained a greater understanding of C/C++.
I''m not saying don''t post questions like this here; I''m saying that we''re here to think through the problem with you. Please post, because that''s what makes these forums worthwhile - the prospect of learning from the questions of others (sorta like a classroom). I''m just saying that once you''ve been pointed in the right direction, you owe it to the forum - the "class" - to do some homework yourself and then come back with your results. That way, everybody learns faster.
Anyway, I''m glad your problem is solved and hopefully you''ve also gained a greater understanding of C/C++.
Using char* is faster than std::string depending what you do.
Why English rules?? C pas très malin tout ça!
Why English rules?? C pas très malin tout ça!
quote:
Original post by jesterlecodeur
Using char* is faster than std::string depending what you do.
Geezes...everyone is in such a hurry these days.
"A society without religion is like a crazed psychopath without a loaded .45"
I''m definately not a fan of the STL.....
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement