Can I pass a string, not previously stored in a vector, as a parameter to a function? [duplicate]

1

I wrote this function to remove the non characters from any string in c:

char *repeticoes(char *s){
    int i=0, j, cont=0;

    while(s[i]!='
int main(void){
    char s[20]="felicidade";    

    printf("%s",repeticoes(s));
}
'){ for(j=0;j<strlen(s);j++) if(s[j]==s[i] & j!=i) break; if(j==strlen(s)) for(j=i;j<strlen(s);j++) s[j]=s[j+1]; else i++; } return s; }
When I pass to it as a vector parameter s, s[20]="felicidade" , I have the expected output that would be "eiidde" , but when I pass as a parameter a *s="felicidade" or simply "felicidade" and command compile, the program does not seem to answer.

It works normally:

int main(void){
    char *s="felicidade";   

    printf("%s",repeticoes(s));
}

do not work:

int main(void){
    printf("%s",repeticoes("felicidade"));
}
char *repeticoes(char *s){
    int i=0, j, cont=0;

    while(s[i]!='
int main(void){
    char s[20]="felicidade";    

    printf("%s",repeticoes(s));
}
'){ for(j=0;j<strlen(s);j++) if(s[j]==s[i] & j!=i) break; if(j==strlen(s)) for(j=i;j<strlen(s);j++) s[j]=s[j+1]; else i++; } return s; }
    
asked by anonymous 29.05.2017 / 20:17

0 answers