Hi everyone! I'm pretty new to C (been messing with it for about three weeks). I've been programming in Java for about two years and before that, BASIC. So, I'm not really new to programming. To help me actually learn C I thought I would code some useful string functions. I successfuly wrote a substring function and now I'm trying to write a function that will remove all occurrances of a certain character in a string and return a copy of that string without the the specified character in it. So, here's my code:
Code:
/**This is in a file named mystring.c**/
char *strsplit(char *string, char delimiter) {
	int len = strlen(string);
	char delimit = delimiter;
	int i;
	int j;
	int numOfTokensFound = 0;
	int newStringLen;
	for(i = 0; i < len; i++) {
		if(string[i] == delimit)
			numOfTokensFound++;
	}
	newStringLen = len - numOfTokensFound;
	char output[newStringLen];
	for(i = 0, j = 0; string[i]; i++, j++) {
		if(string[i] == delimit)
			output[j] = string[i];
	}
	output[j] = '\0';
	return output;
}
In my main program:
Code:
#include "mystring.h"
...
...
main()
{
      ...
      char string[] = "Hello, there!"
      char remove = 'e';
      printf("The string returned by strsplit is:\n%s\n", strsplit(string, e));
      return 0;
}
When I run the program I see that strsplit returns some odd characters. I don't see where I'm going wrong. I would be gratefull if you guys can point me in the right direction.
Also, I'm using gcc3.3 on Mac OS 10.2.6 (don't know if that matters);
Anyways, thanks for your time.