0

This is my code:

include cs50.h

include stdio.h

include ctype.h

int main(){
   int i=0;
   printf("");
   char str[] = GetString();

   printf("%c",*str);
   while(str[i]!='\0'){
      if ((str[i] > 96) && (str[i] < 123)){
        str[i]=str[i]-32; 
      }

      if(str[i]==' '){
            i++;
            printf("%c",*(str+i));
       }
       i++;

   }
   return 0;
}

When I want to make initials, it gives me this error:

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    initials.c  -lcs50 -lm -o initials

initials.c:10:9: error: array initializer must be an initializer list or string literal

char str[] = GetString();

^

1 error generated.

make: *** [initials] Error 1

Please help me figure this out

1 Answer 1

1

The compiler tells you exactly where your problem is. char str[] = GetString(); is an array initializer because char str[] is an array of chars. Try using string str (or char* str) instead of char str[] and you should get a little bit further.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .