标签:des style blog http color io 使用 ar for
#include <stdio.h>
#include <string.h>
void init(int a[][6] ,int m, int n)
{
printf("%d\n",(int)sizeof(a)); //结果是4
}
int main()
{
int a[5][6];
init(a,5,6);
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define M 4
#define N 13
int main()
{
char a[M][N] = {0};
srand(time(NULL));
int n,m,num;
const char X[] = {‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘t‘,‘j‘,‘q‘,‘k‘};
const char Y[] = {‘a‘,‘b‘,‘c‘,‘d‘};
printf("请输入你现在还有几张牌:");
scanf("%d",&num);
while(num>0)
{
m = rand()%4;
n = rand()%13;
if(!a[m][n])
{
a[m][n] = 1;
num--;
printf("%c %c\n",Y[m],X[n]);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
printf("你的名字最多多长:");
scanf("%d", &n);
getchar(); //过滤回车
char * a;
a = (char *)malloc(n * sizeof(char));
printf("请输入你的名字:");
gets(a);
printf("%s\n", a);
free(a);
}
#include <stdio.h>
#include <string.h>
char * str_reverse(char * str)
{
char temp;
int len = strlen(str),i;
for (i = 0; i < len/2; i++)
{
temp = str[i];
str[i] = str[len-i-1];
str[len-i-1] = temp;
}
return str;
}
int main()
{
char s[100] = "hello";
char * p = str_reverse(s);
printf("%s\n",p);
}
#include <stdio.h>
#include <string.h>
int str_times(char * str,char ch)
{
int i = 0;
while(*str != ‘\0‘)
{
if (*str == ch)
i++;
str++;
}
return i;
}
int main()
{
char s[100] = "hello";
printf("%d\n",str_times( s , ‘l‘));
}
sizt_t strlen(const char *s)
{
size_t n = 0;
while(*s++)
n++;
return n;
}
sizt_t strlen(const char *s)
{
const char * p = s;
while(*s)
s++
return s - p;
}
#include <stdio.h>
#include <string.h>
int mb_strlen(const char * p)
{
int len = 0;
while( *p )
{
len++;
if(*p++ < 0)
p++;
}
return len;
}
int main()
{
char *s = "a我b是c你d大e";
int len = mb_strlen( s );
printf("%d\n",len);
return 0;
}
#include <stdio.h>
#include <string.h>
char * str_find(char * str, char * f)
{
while (*str)
{
char * a = str;
char * b = f;
char * res = NULL;
if (*a == *b)
{
res = a;
while (*++a == *++b ) ;
if (*b == ‘\0‘)
return res;
}
str++;
}
return NULL;
}
int main()
{
char *s = "helloworld";
printf("%s\n",str_find(s ,"lo"));
return 0;
}
#include <stdio.h>
#include <string.h>
void str_cpy( char * dest , const char * src)
{
while(*dest++ = *src++);
}
int main()
{
char buf[100] = "aaaaaaaaaaaaaaaaaaaaaaaa";;
str_cpy(buf , "liuwei");
printf("%s\n" , buf);
return 0;
}
#include <stdio.h>
#include <string.h>
char * str_cat(char *p,char *s)
{
char * bak = p;
while(*p)
{
p++;
}
while(*p++ = *s++)
{
}
return bak;
}
int main()
{
char s[10] = "hello";
char v[10] = "world";
printf("%s\n",str_cat(s,v));
return 0;
}
#include <stdio.h>
#include <string.h>
char *str_tok(char * str, const char * de)
{
static char * n;
char * r; //返回的首地址
const char * de_bak = de; //分隔符地址备份
if (str != NULL)
n = str;
r = n;
while (*n)
{
while (*de)
{
if (*n == *de)
{
*n++ = ‘\0‘;
return r;
}
de++;
}
de = de_bak;
n++;
}
if (r == n)
{
return NULL;
}
return r;
}
int main()
{
char s[] = "abcd,cdef,efgh,ghjk";
char *de = ",c";
printf("%s\n", str_tok(s, de));
char *p;
while (p = str_tok(NULL, de))
printf("%s\n", p);
return 0;
}
标签:des style blog http color io 使用 ar for
原文地址:http://www.cnblogs.com/l6241425/p/3951632.html