Here's the deal. I have two arrays. One defining a character set(could be any length), and another defining a string. I want to switch every letter in the string with its placement on the character set. For example:
chrset[256] = "abcdefg"
string[256] = "gfdc"
will turn into:
chrset[256] = "abcdefg"
string[256] = 6, 5, 3, 2
This is my attempt:

#include <stdio.h>
#include <string.h>

int main() {
	unsigned char string[256] = "cba";
	char chrset[256] = "abc";
	int count = 0;
	while(&string[count] != NULL) {
		string[count] = strpbrk(chrset, string[count]); }
	printf("%d", &string);
	return 0; }

You need to test string[count] != 0 in your while condition.
You need to increment count in your loop or you never look past the first character in string.
You probably want strchr, not strpbrk, and you won't want to simply assign it's return value to string[count].
strchr will return the address in chrset, call it p. Then chrset - p will be the offset that you wish to assign to string[count].

Thanks alot. Duh! Incrament the loop!:$ I Think I can get this working now.

This article has been dead for over six months. Start a new discussion instead.