0
warning: assignment makes integer from pointer without a cast [-Wint-conversion]
         category[20] = "Exam";
                      ^
:44:22: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
         category[20] = "Event";
                      ^
    printf("\nChoose what category your task falls under\n1) Exam\n2) Event\n3) Others(Please Specify)\n Pick a Category: ");
    scanf("%d",&choice);
    if (choice == 1)
    {
        category[20] = "Exam";

        b = 1;
    }
    else if (choice == 2)
    {
        category[20] = "Event";
        b = 1;
    }
    else if (choice == 3)
    {
        printf("Please Specify the Category: ");
        scanf("%s", &category);
        b = 1;
    }
    else{
        printf("\nInvalid Category, Try Again");
    }
} while (b != 1);
Gerhardh
  • 11,688
  • 4
  • 17
  • 39
  • You can't assign to an array, only copy to it. This should have been explained by any decent book, tutorial or class. Please do some research about the `strcpy` function. – Some programmer dude May 18 '22 at 06:32
  • It is my first post so im sorry if its not detailed but the issue is that when choice 2 is picked or 1 the string doesnt get printed out on my file instead of "Exam" it ends up as 'x' i have used char character[20]; – Karmveer Singh May 18 '22 at 06:33
  • 1
    Welcome to SO. You should show a complete code that reproduces the problem. We cannot see what `category` is. I assume it is a `char category[20]`. Then in `category[20] = "Exam";` the first part `category[20]` means a single character in that array and you try to assign the address of a string literal which is not possible. Additionally, if you use the size of the array as index, you would access it out of bounds, – Gerhardh May 18 '22 at 06:36
  • The compiler is simply telling you that `category[20] = ` is senseless. You need to study arrays before you can use strings, since strings in C are character arrays. – Lundin May 18 '22 at 06:36
  • @Gerhardh `category` is an array of an integer type such as `char` or otherwise this compiler error wouldn't appear. – Lundin May 18 '22 at 06:37
  • alright i went through it and thanks for explaining it, codes working fine now – Karmveer Singh May 18 '22 at 06:38
  • @Lundin I know that. But the OP should show it and not rely on us to guess it right. – Gerhardh May 18 '22 at 06:39
  • Thanks guys, such a helpful community. My apologies i thought it was like python where you could just assign it like that. With your help the code has been resolved thank you – Karmveer Singh May 18 '22 at 06:40
  • In most cases you should already find a solution if you just search for the error message: *[c] assignment makes integer from pointer without a cast* – Gerhardh May 18 '22 at 06:41

0 Answers0