Please add comments in the code you share ,it will help make things clearer to others.
Always indent your code ,its easy to look at blocks of structured code & make sense of the code.
Always provide initial values to variables ,C language may have garbage initial values to uninitialised variables.
I could not understand why below code was written,but has few issues
int i=0;int j=0;int k; //K can have junk values & could give
//funny results when used as index in array :)
for(;i<len;i++)
{if(str[i]==' ')k=0; //if source string has spaces , k=0
//but what if no spaces are ever found ??
if(str[i]!=' ')
{d[j][k]=str[i];k++; //possible case of garbage value of K read & incremented
if(str[i+1]==' ')
j++;}}
Assuming the word is always a single character & we have to replace all the occurences of that character with a user input character ,below is what i did.
#include <stdio.h>
#include <string.h>
int main(void) {
int len;
char str[100],d[100][100]; //,a[100],b[100];
char a=' ';
char b=' ';
printf("enter the string\n");
scanf("%[^\n]s",str);
len=strlen(str);
int i=0;int j=0;int k;
/*
for(;i<len;i++)
{
if(str[i]==' ') k=0;
if(str[i]!=' ')
{
d[j][k]=str[i];k++;
if(str[i+1]==' ')
j++;
}
}
*/
printf("enter the word to be replaced\n");
scanf(" %c",&a);
printf("enter the replaced word\n");
scanf(" %c",&b);
int l=0;
/*for(;l<=j;l++)
if(strcmp(a,d[l])==0)
strcpy(d[l],b);
*/
for(i=0;i<len;i++)
{
if(str[i]==a)
{
str[i]=b;
}
}
printf("the new string is as folows\n");
printf("%s ",str);
return 0;
}
/*
output
enter the string
sttttringgg
enter the word to be replaced
t
enter the replaced word
x
the new string is as folows
sxxxxringgg
*/