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; }

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.