|
-
May 20th, 2002, 08:31 AM
#1
Filling an array with a string
How would one go about putting the characters of a sting into the index of an array?
eg.
For i = 1 To 8
array(i) = "abcdefgh"
Next
I want array(1) to be a , array(2) to be b and so on.
Thanks
-
May 20th, 2002, 09:46 AM
#2
Code:
memset(arr,'\0',sizeof(arr)); // zero out the array
for (i=1;i<9;i++){
arr[i-1] = i;
}
The problem is: arrays start counting with zero, and zero is used by C to mark the end of a string so:
will create an array with no length - like a null string in VB.
So,
or something like that for the first element
-
May 20th, 2002, 10:51 AM
#3
or this
Code:
char c;
int i=0;
for (c='a';c<='h';c++){
arr[i++]=c;
}
my problem is I have no idea what you want....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|