I am currently working on a small project but have come to a bit of a standstill. At present I have a code that makes two arrays; one containing a series of integers and the other a series of characters. For example:
arrayI = [5, 5, 3]
arrayC = [hellotheresir]
What I want to do, given then integers in the arrayI, is make "words" (as in strings) out of arrayC. To do this I want to take the integer and say given the integer take that many characters out of arrayC, and turn them into a string. Then, continuing from this same point in the arrayC, go to the next integer and do the same thing until both arrays are exhausted. I can also confirm that the integers will always equate to the right number of letters to make the words. In the above example:
First the 5 is taken and checked, and makes a string "hello" (stored somewhere else until done) Then the second 5 is taken from the point the last one left off, and the string "there" is created. Then finally the 3 is taken and the string "sir" is created.
Essentially the integer defines the len of the string to be created.
My code thus far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char** wordList(const char* s) {
char key[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int arr[1000];
char *arry[1000];
int counter = 0;
char * pch;
int pch2;
int count = 0;
pch = strpbrk (s, key);
pch2 = strspn(s, key);
for (int i = 0; i < strlen(s); i++) {
pch2 = strspn(s+i, key);
if ((strspn((s+i)-1, key) == 0) && (pch2 != 0)) {
arr[count] = pch2;
count ++;
}
}
while (pch != NULL) {
arry[counter] = pch;
pch = strpbrk (pch+1, key);
counter ++;
}
return 0;
}
int main (void) {
char** words = wordList("Gadzooks!', he cried.");
}
For reference, the code is simply trying to make an array of words as strings, but I currently only require help with the two arrays part.