>I have a variable:
>char *insert = "abcdefgh"
>and i want to split that into chars like so, 'a', 'b', 'c', 'd', etc.
Uh, you're done. A string literal is an array of const char and except for modification, sizeof, and address-of you can use the pointer as if it were an array. If you need an actual array, you can do this:
char insert[] = "abcdefgh";
C doesn't have a special string type like Java, so when you're using a string in C, you're really using an array.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Hi, I was wonder if someone could give me some help with my program
I have a variable:
char *insert = "abcdefgh"
and i want to split that into chars like so, 'a', 'b', 'c', 'd', etc.
I've tried ToCharArray(), but that doesnt seem to work
a string in c/c++ is a array of characters so extract then like so
#include
int main(int argc, char**argv)
{
char *insert = "abcdefg";
for (int i = 0; i < 7; ++i)
std::cout<
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
This is C forum. Not C/C++ ;)
Take the time to read how properly tag your code so instead of looking like this:
#include
int main(int argc, char**argv)
{
char *insert = "abcdefg";
for (int i = 0; i < 7; ++i)
std::cout<#include <iostream>
int main(int argc, char**argv)
{
char *insert = "abcdefg";
for (int i = 0; i < 7; ++i)
std::cout<<insert[i]<<"\n";
}
For how to do that read here and here
I don't promise that it'll fix your code, but it'll make it more readable.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
>but i'm not sure i'm just a first yr student
If you're not sure, don't answer because you're more likely to lead people astray with bad advice than do any good.
>hee hee
Oh, I get it. You're joking. Because anybody who would jump into a thread over a year after it unofficially ended and offer something as inane as your "help" is either trying to get a laugh or is a complete retard. I don't think you're a complete retard (yet), so it must be a pitiful attempt at humor. :icon_rolleyes:
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
you can do like this: char[] values = {'a','b','c','d','e','f','g'};
then address to each value using the vector(array) like this:
values[0],values[1],etc. (a,b,etc.)
you might want to see this tutorial that has also some detailes about char array: http://goldwin-advertising.ro/index.php?option=com_content&view=article&id=10:splitstring&catid=3:howto&Itemid=5
Yeah they probably figured that out 3 years ago when the question was posted.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387