LoginSignup
0
0

More than 1 year has passed since last update.

C言語には文字列型はない(๑ १д१)<ヒドイ!

Last updated at Posted at 2022-04-15

c言語には文字列型はない(๑ १д१)<ヒドイ!

char string;
string = "ahoboke";

いけない

char *string;
string = "ahoboke";

配列を扱かわせよう

一応検証

#include<stdio.h>
int	main()
{
	char	*str;
	int		i;

	str = "Hello";
	printf("str==>%s\n",str);
	printf("*str==>%c\n",*str);
	while(i < 5)
	{	
		printf("str[%d]==>%c\n", i, str[i]);
		i++;
	}
	i = 0;
	while(i < 5)
	{
		printf("*(str+%d)==>%c\n", i, *(str + i));
		i++;
	}
	return(0);
}

 実行結果

str==>Hello
*str==>H
str[0]==>H
str[1]==>e
str[2]==>l
str[3]==>l
str[4]==>o
*(str+0)==>H
*(str+1)==>e
*(str+2)==>l
*(str+3)==>l
*(str+4)==>o

大城希乃樺

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0