Help me in solving SMILEY problem

My issue

My code

#include <stdio.h>

int main(void) {
	// your code goes here
	int t;
	scanf("%d", &t);
	
	for (t;t>0;t--){
	    int n;
	    scanf("%d", &n);
	    char arr[n+2];
	    int colon[n+2];
	    int cc=0;
	    int sadc=0;
	    int happyc=0;
	    int ans=0;
	    
	    for (int c=0; c<n+1;c++){
	        scanf("%c", &arr[c]);
	        if (arr[c]==':'){
	            colon[cc]=c;
	            cc+=1;
	        }
	    }
	    for(int c=0;c<cc-1;c++){
	        sadc=0;
	        happyc=0;
	        for (int l=colon[c]+1; l<colon[c+1];l++){
	            if (arr[l]==')'){
	                happyc+=1;
	            }
	            else{
	                sadc+=1;
	            }
	        }
	        if (sadc == 0 && happyc>0){
	            ans+=1;
	        }
	    }
	    for (int j=colon[cc-1];j<=n;j++){
	        sadc = 0;
	        happyc = 0;
	        if (arr[j]==')'){
	            happyc+=1;
	        }
	        else{
	            sadc+=1;
	        }
	        
	    }
	    if (sadc == 0 && happyc>0){
	            ans+=1;
	        }
	    
	    printf("%d\n", ans);
	}
	return 0;
}


Problem Link: SMILEY Problem - CodeChef

@kanavkapoor
just few little mistake take input in the form of string outside the loop cozz taking it inside its counting some extra spaces .
i have corrected your code.
include <stdio.h>

int main(void) {
// your code goes here
int t;
scanf(ā€œ%dā€, &t);

for (t;t>0;t--){
    int n;
    scanf("%d", &n);
    char arr[n];
    int colon[n];
    int cc=0;
    int sadc=0;
    int happyc=0;
    int ans=0;
    scanf("%s",arr);
    for (int c=0; c<n;c++){
        if (arr[c]==':'){
            colon[cc]=c;
            cc+=1;
        }
    }
    for(int c=0;c<cc-1;c++){
        sadc=0;
        happyc=0;
        for (int l=colon[c]+1; l<colon[c+1];l++){
            if (arr[l]==')'){
                happyc+=1;
            }
            else{
                sadc+=1;
            }
        }
        if (sadc == 0 && happyc>0){
            ans+=1;
        }
    }
    for (int j=colon[cc-1];j<=n;j++){
        sadc = 0;
        happyc = 0;
        if (arr[j]==')'){
            happyc+=1;
        }
        else{
            sadc+=1;
        }
        
    }
    if (sadc == 0 && happyc>0){
            ans+=1;
        }
    
    printf("%d\n", ans);
}
return 0;

}