Help me debug this code for simple implementation of split strings function

Below code split the strings using a delimiter but due to some reason it is not displaying complete split strings although it displays individual characters of it

#include<bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<b;i++)
#define dbg(x); cout<<"\n"<<#x<<": "<<x<<"\n";
using namespace std;
void splitStr(string str,char delim,string foo[]){
	int k,n,j(0);
	n=str.length();
	f(i,0,n){
		if(str[i]!=delim){
			foo[0][i]=str[i];
		}
		else{
			k=i;
			break;
		}
	}
	foo[0][k]='\0';
	f(i,k+1,n){
		foo[1][j]=str[i];
    	j++;
	}
	foo[1][j]='\0';
}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  	string beautifulLie="dummyXuser",foo[2];
	foo[0]="";
	foo[1]="";
	splitStr(beautifulLie,'X',foo);
	cout<<foo[0]<<"\n";
	cout<<foo[1]<<"\n";
	return 0; 
}

Why aren’t you using in built functions like stringstream and all?

Yeah they are there but I just want to learn their implementation by self

My suggestion use

vector<string>foo(2);

Do you have any clue why this function is not displaying complete strings at the end

I never used string[] so I am unsure

ok

but i tried it outside this function it worked very well

that can be the last option

i tried printing everything in every varibles but didn’t get a clue what went wrong

Line 17 change foo[0][k] to foo[0][i]
Not making a difference but saying to maintain consistency xD

yeah