I'm having trouble with the function 'replace' in my program. The program is supposed to work where the user enters a string of 2 or more words. It first checks to how many times the 1st word is repeated and prints the number. Then it is supposed to replace the 1st word each time it occurs in the string with the second word and print the new string. The function 'replace' is supposed to do the job of replacing the 1st word with the 2nd throughout the string. For some reason, it's not saving anything in my string2.

here's the source...
Code:
#include <stdio.h>
#include <string.h>
#define N 100

void getfirst(const char *string, char *one);
void getsecond(const char *string, char *two);
int stringcount(const char *string, const char *one);
void replace(const char *string, const char *one, const char *two, char *string2);

main()


  {
	char string[N+1]={'\0'}, word1[N+1]={'\0'}, word2[N+1]={'\0'};
	char string2[N+1]={'\0'};
	int number;
	printf("Input a line with at least two words:\n");
	gets(string);
	getfirst(string, word1);
	getsecond(string, word2);
	number = stringcount(string, word1);
	printf("The number of occurrences of the first word %s is %d", word1, number);
	replace(string, word1, word2, string2);
	puts(string2);
	
	return 0;
  }

void getfirst(const char *string, char *one)
  {
	int i;
	
	for(i=0; string[i] != ' '; i++)
	  {
		one[i] = string[i];
	  }
	
  }

void getsecond(const char *string, char *two)
  {
	int i, j;
	
	for(i=0; string[i] != ' '; i++)
		{}
	  for(j=0; string[i]!=' '; j++, i++)
	  {
		two[j] = string[i];
	  }
  }

int stringcount(const char *string, const char *one)
  {
	
	{int i,n,m;
		int count = 0;
		for(i=0; i<N; i++)
			if(one[0] == string[i]){
				for(n=0, m=i; one[n]!='\0' ; n++, m++)
				{
					if( one[n] == string[m])
						{if(one[n+1]=='\0')
							count++;}
					else if(one[n] != string[m])
						continue;
				}
			}
		return count;
	}
  }

void replace(const char *string, const char *one, const char *two, char *string2)
  {
		{int i,n,m,j,k,q=0;
		for(i=0; i<N; i++)
			if(one[0] == string[i]){
				for(n=0, m=i; one[n]!='\0' ; n++, m++)
				{
					if( one[n] == string[m])
						{if(one[n+1]=='\0')
							{for(j=0; j<N; j++, q++)
								string2[q]=two[j];}	
						}
					else if(one[n] != string[m])
						string2[q]=string[i];q++;
				}}
			else if(one[0]!=string[i])
				string2[q] = string[i];
				q++;
			}
  }