我的C语言学习记录
我的C语言## 我的学习之路
这是一篇写给我自己看的博客。
字符串,数组与函数。
字符串有两种常用的定义方法,
char *s="hello everyone",s1[]="lllllllllll",s2[]="gg gg ggg gggg gggg";
第一种方法是使用指针定义,第二种是常规定义
#include <stdio.h>
#include <stdlib.h>
void ex1(int *p)
{
int i=0;
printf("the ex is\n");
for(i-0;i<10;i++)
{
printf("%d\n",*p);
p++;
}
}
void ex2(char *p)
{
int i=0;
while(*p!='\0')
{
printf("%c\n",*p);
p++;
i++;
}
printf("there is %d char\n",i);
}
void ex3(char aa[])
{
int i=0;
while(aa[i]!='\0')
{
printf("%c",aa[i]);
i++;
}
printf("\n");
}
void ex4(int a[])
{
int i=0;
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}
int main()
{
char *s="hello everyone",s1[]="lllllllllll",s2[]="gg gg ggg gggg gggg";
int a[10],i;
for(i=0;i<10;i++)
{
a[i]=rand()%100;
printf("%d ",a[i]);
}
printf("\n");
//gets(s1);
printf("the string is\n");
printf("%s\n",s1);
ex1(a);
ex2("hhhhhhhhhhhhh");
ex2(s);
ex3(s2);
ex4(a);
system("pause");
return 0;
}
函数与字符串的常用方法就这个了