Code of strings


whats causing the seg fault

Hey @singhsimran567
You get segmentation error

  • when you try to access illegal/undefined/unallocated memory
  • when u try to allocate more space than available

Updated ur code and mentioned the changes in comments : https://ide.codingblocks.com/s/385813

the code you provided is still not passing any of the testcase bcoz of an extra , at the end before ]
so how do I fix that

Hey @singhsimran567
You can’t keep track of the last string u print but u can keep track of the first string u are going to print

bool first=true; //to keep track if first string
void strcode(int idx,string arr,string *str,int st){

	if(arr[idx]==NULL){
        if(first==false){ //if not first string then print , before printing the next string
            cout<<", ";
        }	
        cout<<*str; 
        first=false;  //since we printed the string it cant be first anymore
		return;
	}