配列とポインタは同じものではない

こんがらがってたのでメモ。

このコードだとlvalue required as ncrement operandエラーが出る。

#include <stdio.h>

int main(void){
	char str[] = "hello";
	while(*str){
		printf("%c",*str++);
    }
  return 0;
}

正しくはポインタをちゃんと作ってからループを回す。

#include <stdio.h>

int main(void){
	char str[] = "hello";
	char *ps = str;//←ここ
	while(*ps){
		printf("%c",*ps++);
    }
  return 0;		
}