0

Firstly i will show an example:

void main(void){
char word[12];
char input[12];
int i;
printf("Input some word: ");
scanf("%s",input);

for(i=0;i<strlen(input);i++)
    word[i]=NULL;

if(word[i]==NULL){
        printf(" %c ",word[i]);
    }

}

As you can see i give to word[i] a NULL value that makes the warning "Warning assignment makes integer from pointer without a cast", then the next warning is in the if "Warning comparison between pointer and integer". So how can i resolve this warnings, exist other options instead of giving the NULL value?

Fbento49
  • 23
  • 7
  • 1
    `word[i]` (for every valid `i`) is a `char`; `NULL` is not a `char` and (in your implementation) is not compatible so you get the warnings. Use `'\0'` instead of `NULL`. – pmg May 02 '20 at 09:33
  • Okay it works thank you very much. by the way i am new here do i need to do something to the post after the problem is solved? – Fbento49 May 02 '20 at 09:36
  • 1
    If you like one of the answers below, mark it as accepted. You can also mark several as helpful. – pmg May 02 '20 at 09:38

2 Answers2

2

string null terminator is '\0', NULL is usually for pointers.

Tiger Yu
  • 744
  • 3
  • 5
1

Both '\0' and NULL have value 0. The difference is the intent & more-human-readable code.

To learn more, refer to: What is the difference between NULL, '\0' and 0

It has excellent explanations with examples.

MK3
  • 56
  • 8