c语言问题。大家帮忙!

作者&投稿:御山 (若有异议请与网页底部的电邮联系)
简单c语言问题,大家帮忙看看~

putchar是输出一个字符,可是fun()在递归,一直递归到你输入回车就输出c,输出到是从后往前。它会先调用等于回车前的字符输出。比如你输入abcd,那么先用的是f(d),然后输出d,以此往前推。

typedef struct scorebore_fu
{
int opcode;
int dreg;
int qr;
.
.
.
}sb_fu;
注意 ,前面加一个typedef

汗看错了.......
sb_fu *Fu_sta[8];

根本没有给每个指针分配内存!
下面的是使用方式,但是不建议这样使用.
#include
#include
#define N 8

typedef struct scorebore_fu
{
int opcode;
int dreg;
int qr;
} sb_fu;

sb_fu* Fu_sta[N];

int main()
{
int i = 0;

for (i = 0; i < N; i++)
Fu_sta[i] = (sb_fu*)malloc(sizeof(sb_fu));
for (i = 0; i < N; i++)
Fu_sta[i] -> opcode = 0;
for (i = 0; i < N; i++)
free(Fu_sta[i]);

return 0;
}

bcmp(比较内存内容)
相关函数 bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp

表头文件 #include<string.h>

定义函数 int bcmp ( const void *s1,const void * s2,int n);

函数说明 bcmp()用来比较s1和s2所指的内存区间前n个字节,若参数n为0,则返回0。

返回值 若参数s1 和s2 所指的内存内容都完全相同则返回0 值,否则返回非零值。

附加说明 建议使用memcmp()取代。

范例 参考memcmp()。

bcopy(拷贝内存内容)
相关函数 memccpy,memcpy,memmove,strcpy,ctrncpy

表头文件 #include <string.h>

定义函数 void bcopy ( const void *src,void *dest ,int n);

函数说明 bcopy()与memcpy()一样都是用来拷贝src所指的内存内容前n个字节到dest所指的地址,不过参数src与dest在传给函数时是相反的位置。

返回值

附加说明 建议使用memcpy()取代

范例 #include<string.h>
main()
{
char dest[30]=”string(a)”;
char src[30]=”string\0string”;
int i;
bcopy(src,dest,30);/* src指针放在前*/
printf(bcopy(): “)
for(i=0;i<30;i++)
printf(“%c”,dest[i]);
memcpy(dest src,30); /*dest指针放在钱*/
printf(‘\nmemcpy() : “);
for(i=0;i<30;i++)
printf(“%c”,dest[i]);

执行 bcopy() : string string
memcpy() :string sring

bzero(将一段内存内容全清为零)
相关函数 memset,swab

表头文件 #include<string.h>

定义函数 void bzero(void *s,int n);

函数说明 bzero()会将参数s所指的内存区域前n个字节,全部设为零值。相当于调用memset((void*)s,0,size_tn);

返回值

附加说明 建议使用memset取代

范例 参考memset()。

index(查找字符串中第一个出现的指定字符)
相关函数 rindex,srechr,strrchr

表头文件 #include<string.h>

定义函数 char * index( const char *s, int c);

函数说明 index()用来找出参数s字符串中第一个出现的参数c地址,然后将该字符出现的地址返回。字符串结束字符(NULL)也视为字符串一部分。

返回值 如果找到指定的字符则返回该字符所在地址,否则返回0。

范例 #include<string.h>
main()
{
char *s =”0123456789012345678901234567890”;
char *p;
p =index(s,’5’);
printf(%s\n”,p);
}

执行 5.68E+25

memccpy(拷贝内存内容)
相关函数 bcopy,memcpy,memmove,strcpy,strncpy

表头文件 #include<string.h>

定义函数 void * memccpy(void *dest, const void * src, int c,size_t n);

函数说明 memccpy()用来拷贝src所指的内存内容前n个字节到dest所指的地址上。与memcpy()不同的是,memccpy()会在复制时检查参数c是否出现,若是则返回dest中值为c的下一个字节地址。

返回值 返回指向dest中值为c的下一个字节指针。返回值为0表示在src所指内存前n个字节中没有值为c的字节。

范例 #include<string.h>
main()
{
char a[]="string[a]";
char b[]="string(b)";
memccpy(a,b,'B',sizeof(b));
printf("memccpy():%s\n",a);
}

执行 memccpy():string(b)

memchr(在某一内存范围中查找一特定字符)
相关函数 index,rindex,strchr,strpbrk,strrchr,strsep,strspn,strstr

表头文件 #include<string.h>

定义函数 void * memchr(const void *s,int c,size_t n);

函数说明 memchr()从头开始搜寻s所指的内存内容前n个字节,直到发现第一个值为c的字节,则返回指向该字节的指针。

返回值 如果找到指定的字节则返回该字节的指针,否则返回0。

范例 #include <string.h>
main()
{
char *s="0123456789012345678901234567890";
char *p;
p=memchr(s,'5',10);
printf("%s\n",p);
}

执行 5.68E+25

memcmp(比较内存内容)
相关函数 bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp

表头文件 #include<string.h>

定义函数 int memcmp (const void *s1,const void *s2,size_t n);

函数说明 memcmp()用来比较s1和s2所指的内存区间前n个字符。字符串大小的比较是以ASCII码表上的顺序来决定,次顺序亦为字符的值。memcmp()首先将s1第一个字符值减去s2第一个字符的值,若差为0则再继续比较下个字符,若差值不为0则将差值返回。例如,字符串"Ac"和"ba"比较则会返回字符'A'(65)和'b'(98)的差值(-33)。

返回值 若参数s1和s2所指的内存内容都完全相同则返回0值。s1若大于s2则返回大于0的值。s1若小于s2则返回小于0的值。

范例 #include<string.h>
main()
{
char *a ="aBcDeF";
char *b="AbCdEf";
char *c="aacdef";
char *d="aBcDeF";
printf("memcmp(a,b):%d\n",memcmp((void*)a,(void*) b,6));
printf("memcmp(a,c):%d\n",memcmp((void*)a,(void*) c,6));
printf("memcmp(a,d):%d\n",memcmp((void*)a,(void*) d,6));

执行 memcmp(a,b):1 /*字符串a>字符串b,返回1*/
memcmp(a,c):-1 /* 字符串a<字符串c,返回-1*/
memcmp(a,d):0 /*字符串a=字符串d,返回0*/

memcpy(拷贝内存内容)
相关函数 bcopy,memccpy,memcpy,memmove,strcpy,strncpy

表头文件 #include<string.h>

定义函数 void * memcpy (void * dest ,const void *src, size_t n);

函数说明 memcpy()用来拷贝src所指的内存内容前n个字节到dest所指的内存地址上。与strcpy()不同的是,memcpy()会完整的复制n个字节,不会因为遇到字符串结束'\0'而结束。

返回值 返回指向dest的指针。

附加说明 指针src和dest所指的内存区域不可重叠。

范例 #include<string.h>
main()
{
char a[30]="string (a)";
char b[30]="string\0string";
int i;
strcpy(a,b);
printf("strcpy():");
for(i=0;i<30;i++)
printf("%c",a[i]);
memcpy(a,b,30);
printf("\nmemcpy() :");
for(i=0;i<30;i++)
printf("%c",a[i]);
}

执行 strcpy() : string a )
memcpy() : string string

memmove(拷贝内存内容)
相关函数 bcopy,memccpy,memcpy,strcpy,strncpy

表头文件 #include<string.h>

定义函数 void * memmove(void *dest,const void *src,size_t n);

函数说明 memmove()与memcpy()一样都是用来拷贝src所指的内存内容前n个字节到dest所指的地址上。不同的是,当src和dest所指的内存区域重叠时,memmove()仍然可以正确的处理,不过执行效率上会比使用memcpy()略慢些。

返回值 返回指向dest的指针。

附加说明 指针src和dest所指的内存区域可以重叠。

范例 参考memcpy()。

memset(将一段内存空间填入某值)
相关函数 bzero,swab

表头文件 #include<string.h>

定义函数 void * memset (void *s ,int c, size_t n);

函数说明 memset()会将参数s所指的内存区域前n个字节以参数c填入,然后返回指向s的指针。在编写程序时,若需要将某一数组作初始化,memset()会相当方便。

返回值 返回指向s的指针。

附加说明 参数c虽声明为int, 但必须是unsigned char ,所以范围在0到255之间。

范例 #include <string.h>
main()
{
char s[30];
memset (s,'A',sizeof(s));
s[30]='\0';
printf("%s\n",s);
}

执行 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

rindex(查找字符串中最后一个出现的指定字符)
相关函数 index,memchr,strchr,strrchr

表头文件 #include<string.h>

定义函数 char * rindex( const char *s,int c);

函数说明 rindex()用来找出参数s字符串中最后一个出现的参数c地址,然后将该字符出现的地址返回。字符串结束字符(NULL)也视为字符串一部分。

返回值 如果找到指定的字符则返回该字符所在的地址,否则返回0。

范例 #include <string.h>
mian()
{
char *s ="0123456789012345678901234567890";
char *p;
p=rindex(s,'5');
printf("%s\n",p);
}

执行 567890

strcasecmp(忽略大小写比较字符串)
相关函数 bcmp,memcmp,strcmp,strcoll,strncmp

表头文件 #include<string.h>

定义函数 int strcasecmp (const char *s1, const char *s2);

函数说明 strcasecmp()用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。

返回值 若参数s1和s2字符串相同则返回0。s1长度大于s2长度则返回大于0 的值,s1 长度若小于s2 长度则返回小于0的值。

范例 #include <string.h>
main()
{
char *a="aBcDeF";
char *b="AbCdEf";
if(!strcasecmp(a,b))
printf("%s=%s\n",a,b);
}

执行 aBcDeF=AbCdEf

strcat(连接两字符串)
相关函数 bcopy,memccpy,memcpy,strcpy,strncpy

表头文件 #include <string.h>

定义函数 char *strcat (char *dest,const char *src);

函数说明 strcat()会将参数src字符串拷贝到参数dest所指的字符串尾。第一个参数dest要有足够的空间来容纳要拷贝的字符串。

返回值 返回参数dest的字符串起始地址

范例 #include <string.h.>
main()
{
char a[30]="string(1)";
char b[]="string(2)";
printf("before strcat() : %s\n",a);
printf("after strcat() : %s\n",strcat(a,b));
}

执行 before strcat () : string(1)
after strcat () : string(1)string(2)

strchr(查找字符串中第一个出现的指定字符)
相关函数 index,memchr,rinex,strbrk,strsep,strspn,strstr,strtok

表头文件 #include<string.h>

定义函数 char * strchr (const char *s,int c);

函数说明 strchr()用来找出参数s字符串中第一个出现的参数c地址,然后将该字符出现的地址返回。

返回值 如果找到指定的字符则返回该字符所在地址,否则返回0。

范例 #include<string.h>
main()
{
char *s=0123456789012345678901234567890”;
char *p;
p=strchr(s,'5');
printf("%s\n",p);
}

执行 5.68E+25

strcmp(比较字符串)
相关函数 bcmp,memcmp,strcasecmp,strncasecmp,strcoll

表头文件 #include<string.h>

定义函数 int strcmp(const char *s1,const char *s2);

函数说明 strcmp()用来比较参数s1和s2字符串。字符串大小的比较是以ASCII 码表上的顺序来决定,此顺序亦为字符的值。strcmp()首先将s1第一个字符值减去s2第一个字符值,若差值为0则再继续比较下个字符,若差值不为0则将差值返回。例如字符串"Ac"和"ba"比较则会返回字符"A"(65)和'b'(98)的差值(-33)。

返回值 若参数s1和s2字符串相同则返回0。s1若大于s2则返回大于0的值。s1若小于s2则返回小于0 的值。

范例 #include<string.h>
main()
{
char *a="aBcDeF";
char *b="AbCdEf";
char *c="aacdef";
char *d="aBcDeF";
printf("strcmp(a,b) : %d\n",strcmp(a,b));
printf("strcmp(a,c) : %d\n",strcmp(a,c));
printf("strcmp(a,d) : %d\n",strcmp(a,d));
}

执行 strcmp(a,b) : 32
strcmp(a,c) :-31
strcmp(a,d) : 0

strcoll(采用目前区域的字符排列次序来比较字符串)
相关函数 strcmp,bcmp,memcmp,strcasecmp,strncasecmp

表头文件 #include<string.h>

定义函数 int strcoll( const char *s1, const char *s2);

函数说明 strcoll()会依环境变量LC_COLLATE所指定的文字排列次序来比较s1和s2 字符串。

返回值 若参数s1和s2字符串相同则返回0。s1若大于s2则返回大于0的值。s1若小于s2则返回小于0 的值。

附加说明 若LC_COLLATE为"POSIX"或"C",则strcoll()与strcmp()作用完全相同。

范例 参考strcmp()。

strcpy(拷贝字符串)
相关函数 bcopy,memcpy,memccpy,memmove

表头文件 #include<string.h>

定义函数 char *strcpy(char *dest,const char *src);

函数说明 strcpy()会将参数src字符串拷贝至参数dest所指的地址。

返回值 返回参数dest的字符串起始地址。

附加说明 如果参数dest所指的内存空间不够大,可能会造成缓冲溢出(buffer Overflow)的错误情况,在编写程序时请特别留意,或者用strncpy()来取代。

范例 #include<string.h>
main()
{
char a[30]="string(1)";
char b[]="string(2)";
printf("before strcpy() :%s\n",a);
printf("after strcpy() :%s\n",strcpy(a,b));
}

执行 before strcpy() :string(1)
after strcpy() :string(2)

strcspn(返回字符串中连续不含指定字符串内容的字符数)
相关函数 strspn

表头文件 #inclued<string.h>

定义函数 size_t strcspn ( const char *s,const char * reject);

函数说明 strcspn()从参数s字符串的开头计算连续的字符,而这些字符都完全不在参数reject 所指的字符串中。简单地说,若strcspn()返回的数值为n,则代表字符串s开头连续有n个字符都不含字符串reject内的字符。

返回值 返回字符串s开头连续不含字符串reject内的字符数目。

范例 #include <string.h>
main()
{
char *str="Linux was first developed for 386/486-based pcs.";
printf("%d\n",strcspn(str," "));
printf("%d\n",strcspn(str,"/-"));
printf("%d\n",strcspn(str,"1234567890"));
}

执行 5 /*只计算到“ ”的出现,所以返回“Linux”的长度*/
33 /*计算到出现“/”或“-”,所以返回到“6”的长度*/
30 /* 计算到出现数字字符为止,所以返回“3”出现前的长度*/

strdup(复制字符串)
相关函数 calloc,malloc,realloc,free

表头文件 #include<string.h>

定义函数 char * strdup( const char *s);

函数说明 strdup()会先用maolloc()配置与参数s字符串相同的空间大小,然后将参数s字符串的内容复制到该内存地址,然后把该地址返回。该地址最后可以利用free()来释放。

返回值 返回一字符串指针,该指针指向复制后的新字符串地址。若返回NULL表示内存不足。

范例 #include<string.h>
main()
{
char a[]="strdup";
char *b;
b=strdup(a);
printf("b[ ]=\"%s\"\n",b);
}

执行 b[ ]="strdup"

strlen(返回字符串长度)
相关函数

表头文件 #include<string.h>

定义函数 size_t strlen (const char *s);

函数说明 strlen()用来计算指定的字符串s的长度,不包括结束字符"\0"。

返回值 返回字符串s的字符数。

范例 /*取得字符串str的长度*/
#include<string.h>
main()
{
char *str = "12345678";
printf("str length = %d\n", strlen(str));
}

执行 str length = 8

strncasecmp(忽略大小写比较字符串)
相关函数 bcmp,memcmp,strcmp,strcoll,strncmp

表头文件 #include<string.h>

定义函数 int strncasecmp(const char *s1,const char *s2,size_t n);

函数说明 strncasecmp()用来比较参数s1和s2字符串前n个字符,比较时会自动忽略大小写的差异。

返回值 若参数s1和s2 字符串相同则返回0。s1 若大于s2则返回大于0的值,s1若小于s2则返回小于0 的值。

范例 #include<string.h>
main()
{
char *a="aBcDeF";
char *b="AbCdEf";
if(!strncasecmp(a,b))
printf("%s =%s\n",a,b);
}

执行 aBcDef=AbCdEf

strncat(连接两字符串)
相关函数 bcopy,memccpy,memecpy,strcpy,strncpy

表头文件 #inclue <string.h>

定义函数 char * strncat(char *dest,const char *src,size_t n);

函数说明 strncat()会将参数src字符串拷贝n个字符到参数dest所指的字符串尾。第一个参数dest要有足够的空间来容纳要拷贝的字符串。

返回值 返回参数dest的字符串起始地址。

范例 #include <string.h>
main()
{
char a[30]="string(1)";
char b[]="string(2)";
printf("before strnact() :%s\n", a);
printf("after strncat() :%s\n", strncat(a,b,6));
}

执行 before strnact() : string(1)
after strncat() : string(1) string

strncpy(拷贝字符串)
相关函数 bcopy,memccpy,memcpy,memmove

表头文件 #include<string.h>

定义函数 char * strncpy(char *dest,const char *src,size_t n);

函数说明 strncpy()会将参数src字符串拷贝前n个字符至参数dest所指的地址。

返回值 返回参数dest的字符串起始地址。

范例 #inclue <string.h>
main()
{
char a[30]="string(1)";
char b[]="string(2)";
printf("before strncpy() : %s\n",a);
printf("after strncpy() : %s\n",strncpy(a,b,6));
}

执行 before strncpy() : string(1)
after strncpy() : string(1)

strpbrk(查找字符串中第一个出现的指定字符)
相关函数 index,memchr,rindex,strpbrk,strsep,strspn,strstr,strtok

表头文件 #include <include.h>

定义函数 char *strpbrk(const char *s,const char *accept);

函数说明 strpbrk()用来找出参数s 字符串中最先出现存在参数accept 字符串中的任意字符。

返回值 如果找到指定的字符则返回该字符所在地址,否则返回0。

范例 #include <string.h>
main()
{
char *s="0123456789012345678901234567890";
char *p;
p=strpbrk(s,"a1 839"); /*1会最先在s字符串中找到*/
printf("%s\n",p);
p=strprk(s,"4398");/*3 会最先在s 字符串中找到*/
printf("%s\n",p);

执行 1.23E+29

strrchr(查找字符串中最后出现的指定字符)
相关函数 index,memchr,rindex,strpbrk,strsep,strspn,strstr,strtok

表头文件 #include<string.h>

定义函数 char * strrchr(const char *s, int c);

函数说明 strrchr()用来找出参数s字符串中最后一个出现的参数c地址,然后将该字符出现的地址返回。

返回值 如果找到指定的字符则返回该字符所在地址,否则返回0。

范例 #include<string.h>
main()
{
char *s="0123456789012345678901234567890";
char *p;
p=strrchr(s,'5');
printf("%s\n",p);
}

执行 567890

strspn(返回字符串中连续不含指定字符串内容的字符数)
相关函数 strcspn,strchr,strpbrk,strsep,strstr

表头文件 #include<string.h>

定义函数 size_t strspn (const char *s,const char * accept);

函数说明 strspn()从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept 所指字符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n 个字符都是属于字符串accept内的字符。

返回值 返回字符串s开头连续包含字符串accept内的字符数目。

范例 #include<string.h>
main()
{
char *str="Linux was first developed for 386/486-based PCs.";
char *t1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
printf("%d\n",strspn(str,t1));
}

执行 5 /*计算大小写字母。不包含“ ”,所以返回Linux的长度。*/

strstr(在一字符串中查找指定的字符串)
相关函数 index,memchr,rindex,strchr,strpbrk,strsep,strspn,strtok

表头文件 #include<string.h>

定义函数 char *strstr(const char *haystack,const char *needle);

函数说明 strstr()会从字符串haystack 中搜寻字符串needle,并将第一次出现的地址返回。

返回值 返回指定字符串第一次出现的地址,否则返回0。

范例 #include<string.h>
main()
{
char * s="012345678901234567890123456789";
char *p;
p= strstr(s,"901");
printf("%s\n",p);
}

执行 9.01E+21

strtok(分割字符串)
相关函数 index,memchr,rindex,strpbrk,strsep,strspn,strstr

表头文件 #include<string.h>

定义函数 char * strtok(char *s,const char *delim);

函数说明 strtok()用来将字符串分割成一个个片段。参数s指向欲分割的字符串,参数delim则为分割字符串,当strtok()在参数s的字符串中发现到参数delim的分割字符时则会将该字符改为\0 字符。在第一次调用时,strtok()必需给予参数s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回下一个分割后的字符串指针。

返回值 返回下一个分割后的字符串指针,如果已无从分割则返回NULL。

范例 #include<string.h>
main()
{
char s[]="ab-cd : ef;gh :i-jkl;mnop;qrs-tu: vwx-y;z";
char *delim="-: ";
char *p;
printf("%s ";strtok(s,delim));
while((p=strtok(NULL,delim)))printf("%s ",p);
printf("\n");
}

执行 ab cd ef;gh i jkl;mnop;qrs tu vwx y;z /*-与:字符已经被\0 字符取代*/

指针变量32位机器占4个字节,16位机器占2个字节,与整型数相同。

字符串处理函数的用法我贴出来,返回值函数原形有。
一般测量长度,返回int 值。
连接,拷贝等返回字符串指针。
如果是内存操作函数一般返回void*而不是char*。

函数名: strcpy
功 能: 拷贝一个字符串到另一个
用 法: char *strcpy(char *destin, char *source);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char string[10];
char *str1 = "abcdefghi";

strcpy(string, str1);
printf("%s\n", string);
return 0;
}

函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";

strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);

printf("%s\n", destination);
return 0;
}

函数名: strchr
功 能: 在一个串中查找给定字符的第一个匹配之处\
用 法: char *strchr(char *str, char c);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char string[15];
char *ptr, c = 'r';

strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}

函数名: strcmp
功 能: 串比较
用 法: int strcmp(char *str1, char *str2);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;

ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");

ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");

return 0;
}

函数名: strncmpi
功 能: 将一个串中的一部分与另一个串比较, 不管大小写
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;

ptr = strcmpi(buf2, buf1);

if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");

if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");

if (ptr == 0)
printf("buffer 2 equals buffer 1\n");

return 0;
}

函数名: strcpy
功 能: 串拷贝
用 法: char *strcpy(char *str1, char *str2);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char string[10];
char *str1 = "abcdefghi";

strcpy(string, str1);
printf("%s\n", string);
return 0;
}

函数名: strcspn
功 能: 在串中查找第一个给定字符集内容的段
用 法: int strcspn(char *str1, char *str2);
程序例:

#include <stdio.h>
#include <string.h>
#include <alloc.h>

int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;

length = strcspn(string1, string2);
printf("Character where strings intersect is at position %d\n", length);

return 0;
}

函数名: strdup
功 能: 将串拷贝到新建的位置处
用 法: char *strdup(char *str);
程序例:

#include <stdio.h>
#include <string.h>
#include <alloc.h>

int main(void)
{
char *dup_str, *string = "abcde";

dup_str = strdup(string);
printf("%s\n", dup_str);
free(dup_str);

return 0;
}

函数名: stricmp
功 能: 以大小写不敏感方式比较两个串
用 法: int stricmp(char *str1, char *str2);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;

ptr = stricmp(buf2, buf1);

if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");

if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");

if (ptr == 0)
printf("buffer 2 equals buffer 1\n");

return 0;
}

函数名: strerror
功 能: 返回指向错误信息字符串的指针
用 法: char *strerror(int errnum);
程序例:

#include <stdio.h>
#include <errno.h>

int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s\n", buffer);
return 0;
}

函数名: strcmpi
功 能: 将一个串与另一个比较, 不管大小写
用 法: int strcmpi(char *str1, char *str2);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;

ptr = strcmpi(buf2, buf1);

if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");

if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");

if (ptr == 0)
printf("buffer 2 equals buffer 1\n");

return 0;
}

函数名: strncmp
功 能: 串比较
用 法: int strncmp(char *str1, char *str2, int maxlen);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)

{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;

ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");

ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");

return(0);
}

函数名: strncmpi
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
用 法: int strncmpi(char *str1, char *str2);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;

ptr = strncmpi(buf2,buf1,3);

if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");

if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");

if (ptr == 0)
printf("buffer 2 equals buffer 1\n");

return 0;
}

函数名: strncpy
功 能: 串拷贝
用 法: char *strncpy(char *destin, char *source, int maxlen);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char string[10];
char *str1 = "abcdefghi";

strncpy(string, str1, 3);
string[3] = '\0';
printf("%s\n", string);
return 0;
}

函数名: strnicmp
功 能: 不注重大小写地比较两个串
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;

ptr = strnicmp(buf2, buf1, 3);

if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");

if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");

if (ptr == 0)
printf("buffer 2 equals buffer 1\n");

return 0;
}

函数名: strnset
功 能: 将一个串中的所有字符都设为指定字符
用 法: char *strnset(char *str, char ch, unsigned n);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';

printf("string before strnset: %s\n", string);
strnset(string, letter, 13);
printf("string after strnset: %s\n", string);

return 0;
}

函数名: strpbrk
功 能: 在串中查找给定字符集中的字符
用 法: char *strpbrk(char *str1, char *str2);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr;

ptr = strpbrk(string1, string2);

if (ptr)
printf("strpbrk found first character: %c\n", *ptr);
else
printf("strpbrk didn't find character in set\n");

return 0;
}

函数名: strrchr
功 能: 在串中查找指定字符的最后一个出现
用 法: char *strrchr(char *str, char c);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char string[15];
char *ptr, c = 'r';

strcpy(string, "This is a string");
ptr = strrchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}

函数名: strrev
功 能: 串倒转
用 法: char *strrev(char *str);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char *forward = "string";

printf("Before strrev(): %s\n", forward);
strrev(forward);
printf("After strrev(): %s\n", forward);
return 0;
}

函数名: strset
功 能: 将一个串中的所有字符都设为指定字符
用 法: char *strset(char *str, char c);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char string[10] = "123456789";
char symbol = 'c';

printf("Before strset(): %s\n", string);
strset(string, symbol);
printf("After strset(): %s\n", string);
return 0;
}

函数名: strspn
功 能: 在串中查找指定字符集的子集的第一次出现
用 法: int strspn(char *str1, char *str2);
程序例:

#include <stdio.h>
#include <string.h>
#include <alloc.h>

int main(void)
{
char *string1 = "1234567890";
char *string2 = "123DC8";
int length;

length = strspn(string1, string2);
printf("Character where strings differ is at position %d\n", length);
return 0;
}

函数名: strstr
功 能: 在串中查找指定字符串的第一次出现
用 法: char *strstr(char *str1, char *str2);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;

ptr = strstr(str1, str2);
printf("The substring is: %s\n", ptr);
return 0;
}

函数名: strtod
功 能: 将字符串转换为double型值
用 法: double strtod(char *str, char **endptr);
程序例:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char input[80], *endptr;
double value;

printf("Enter a floating point number:");
gets(input);
value = strtod(input, &endptr);
printf("The string is %s the number is %lf\n", input, value);
return 0;
}

函数名: strtok
功 能: 查找由在第二个串中指定的分界符分隔开的单词
用 法: char *strtok(char *str1, char *str2);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
char input[16] = "abc,d";
char *p;

/* strtok places a NULL terminator
in front of the token, if found */
p = strtok(input, ",");
if (p) printf("%s\n", p);

/* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
p = strtok(NULL, ",");
if (p) printf("%s\n", p);
return 0;
}

函数名: strtol
功 能: 将串转换为长整数
用 法: long strtol(char *str, char **endptr, int base);
程序例:

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
char *string = "87654321", *endptr;
long lnumber;

/* strtol converts string to long integer */
lnumber = strtol(string, &endptr, 10);
printf("string = %s long = %ld\n", string, lnumber);

return 0;
}

函数名: strupr
功 能: 将串中的小写字母转换为大写字母
用 法: char *strupr(char *str);
程序例:

#include <stdio.h>
#include <string.h>

int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;

/* converts string to upper case characters */
ptr = strupr(string);
printf("%s\n", ptr);
return 0;
}

连接 返回值 连接后的字符串指针。例如
char str[32]="abc";
printf("%s", strcat(str,".ccc"));
打出结果 abc.ccc 与 str里的结果相同。

复制, 返回值, 复制后的字符串指针
printf("%s", strcpy(str,"xyz")) ;
打出结果 xyz, 与 str里的结果相同

比较 strcmp, 返回int 值, 为0 表明 相等,非零 为 不等。

测量长度,返回int 值,表示长度字节数

字符转换,不属标准 字符串处理函数

指针变量本身 是无符号整型数,字长与机器有关,一般32位。它的值是指向的地址。


C语言问题,跪求大神帮忙,新人一枚
我认为C就是0了,因为A&B是位运算,B=0,想与所以A&B=0,不管C为何值,B为0,所以想与B&C=0;然后&&是逻辑运算,所以C=0;if(3&1)是真的,3&1实际为11&01;相同为1,不同为0,所以3&1=1,在if语句中表示真。

计算机有关c语言的一些问题选择 各位大大 求帮忙~~~
其中不能有大于f的就行、第十三题:b d 理由:a是一关系表达式,b是语句,c中不合法,赋值运算符的左侧必须是变量,d正确 第十四题:c 理由:编译后生成的是目标文件后缀是.obj连接后生成的是可执行文件后缀是.exe 这些都是最基础的东西 最好是多看看课本 希望可以对你有所帮助 ...

C语言的问题:请大神帮忙作答。 int a1,a2; char c1,c2; scanf("%d%c...
c是识别空格、回车的,而%d是不识别的。而且其实不用两个空格也可以输入10A20B的

宝宝说话出问题“语言治疗”来帮忙
到了一定的年龄,宝宝依然口齿不清,或者不会说话,家长们开始着急,开始寻求各种帮助,有时候茫然不知所措,闯遍各大科室却收效甚微。近几年迎来不少这样的宝宝,他们有的到了3、4岁还没开始说话,有的吐字不清,有的孩子表现出与同龄孩子偏低的智力,有的孩子口吃……其实,这种宝宝可能存在语言障碍...

二级c语言有几个不懂的问题,希望大家帮忙解疑
第一个:fun函数其实就是排序,从大到小。一个概念:逆序。一列数,小的在大的前叫一个逆序,则N个数,逆序数最大为N*N\/2 for (i=0 ;i<n-1;i++)\/\/循环N次 for(j=i+1;j<n;j++)\/\/消除n-1-i个逆序 { if(a[i]

请教一个简单的C语言问题,请大家帮帮忙~~
,那么 你输入时也必须有逗号 否则出错 所以一般不这么输入 用也应该有提示 而里面的 内容 %2d %3d 意思是2位用来显示 不足补齐超出继续 你输入的是 123 那么12 这是2位 用来输出 而剩下3 取3位补齐 还是3 你第二次用的 123 这号成为了 下次的读取操作 还有什么细节问题 你再补充吧 ...

一道C语言编程问题,高手们来看看帮忙解答下
先推算公式,C^2*(A^2+B^2),= (A^2*B^2),程序就是找寻能让公式左右相等的ABC的值,且0<c<b<a<100.include <stdio.h> int main(){ int a;\/\/定义循环变量。int b;int c;int sum;\/\/ABC之和。for (a = 100;a > 0;a--)\/\/以A为循环变量,在1到100之间。{ for (b = ...

今天听到一个最有趣的问题,大家也帮忙想想,话说,如果昨天是明天就好了...
而是个汉语言学问题。为了加深理解,我们换个题。”唉,今天是9号,昨天是明天就好了“是想表达什么意思?可能是想说“如果昨天是10号就好了”,也可能是“如果8号是明天就好了”。当然,前一种符合这个表达方式的普遍使用习惯,后一种,你读读,也不能说完全错。希望回答对大家有帮助!

用C语言求根问题,请大家帮忙看下,我觉得程序没错,但就是运行不对...
程序没有错误,是逻辑错误。我运行了没有错误。include<stdio.h>#include <math.h>#define f(x) 2*pow(x,3)-4*pow(x,2)+3*x-6int main(){ double x1,x2,x0; scanf("%lf%lf",&x1,&x2); x0=(x1+x2)\/2; while (f(x0)>1e-3) { if (f(x0)*f(x1)<0) {...

c语言问题,大家速度进,明天要机试了!~20分悬赏啊
n%10+'0'的意思是n%10得到的是一个整型的实数,而加上‘0’就变成了字符了;n\/10意思是去掉n的最后一位数, 然后继续前面的循环,

招远市19158506450: C语言问题,求大家帮忙【1】 假设字母a、b、c、d、e、f的霍夫曼编码分别是1、00、011、0100、01010、01011.那么字符串“abcdef”的编码显然就是... -
茅胥奥力:[答案] 用java写的,作参考:public class EnCode { public static void main(String[] args) { int[] a = new int[] { 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0 }; print(a); } public static void print(int[] a) { for (int i = 0; i < a.length; ++i) { if (a[i] == 1) ...

招远市19158506450: C语言问题.大家帮帮忙啊! -
茅胥奥力: #include int sushu(int n){ int i; for(i=2;i<=(int)sqrt((double)n);i++) { if(n%i==0) { return 0; } } return 1;}int main() { int i,k,...

招远市19158506450: c语言小问题 高手帮忙 -
茅胥奥力: 1关闭软件,重新打开软件,再编程试试 2你看看编译那有没有这个提示compiling... error spawning cl.exe ,如果有的话 解决方法如下: 方法一:把软件卸载,重新装一遍 方法二:有点麻烦,但不用重装软件打开 Microsoft Visual C++ -->工具 --...

招远市19158506450: C语言提问,大家帮忙
茅胥奥力: #include <stdio.h> #include <ctype.h> #include <string.h> int main() { char a[21],i=0,t; printf("enter characters:"); gets(a); for(t=0;a[t]!='\0';t++) if (islower(a[t])) i+=1; printf("Final Score: %d",i); getch(); return 0; }

招远市19158506450: 问几道C语言题,请大家帮忙解决:
茅胥奥力: 1. D A: 我觉得不对.例如{}是可以分割语句的. B: 是因为可以将整形自动转换成实型 C: 实数不一定能准确表示 2. B.很显然B是对的. 3. B.画画图就知道了,用归纳法应该可以证明. 4. pow(2, n) &lt;= i, j &lt; pow(2, n+1) - 1 (关系应该是这样的,不是很肯定这种写法好不好) 5. A.不是特别确定,严格来说应该是有两个函数调用,所以应该有6个实参才对.

招远市19158506450: 有几个C语言的编程问题想请教下大家,谢谢帮忙!
茅胥奥力: #include "stdio.h" void main() { char ch; printf ("please input char:\n"); ch=getchar();/*输入一个字符*/ if (ch>='A'&&ch<='Z') /*进行判断是不是大写*/printf ("%c",ch+32);elseprintf ("非法字符");} turboC编译 给你做个参考吧!自己做自己思考才有进步... 祝你生活愉快

招远市19158506450: 又是C语言题,大家帮帮忙,急啊!都挺简单的.谢! -
茅胥奥力: 1. 数组类型,结构类型,联合类型2. false,true 3. a=1,b=3,c=24. fp=fopen("d1.dat","r");5. 15,'m'6. "a"为字符串,占两字节;a为字符,占一字节7. 一个内存地址,取地址操作8. C语言规定标识符只能由字母、数字和下划线三种字符组成,且第一个字符必须为字母或下划线.9. 编辑,编译,连接,调试

招远市19158506450: 有一些关于C语言的问题~请大家帮帮忙~悬赏100分 -
茅胥奥力: 最后两题,楼上的写错了 第3题要对c赋值的 第4题是t不是f一、 1、6 8 2、3.141593,3.1416,3.142 3、4 4、2,4 5、8 6、sum=11 7、AB 8、People's Republic ofChina二、 1、 (i==j) (i+j==2) 2、 scanf("%f",&f); sum+=f; 3、 ((c=string[i])!='\0') (c!=' '&&word==0) 4、 t=a; a=b; b=t;

招远市19158506450: c语言,大家快来帮忙啊 -
茅胥奥力: 第一问:(5/2)两个整数相除,等到结果直接取整为2,因为前面加了(double)所以(double)(5/2)这一句的结果为2.00(后面多少个零不同编译器会不同),剩下的你懂了吧.第二问:a++的值为5,但是在运算完后才是6.因为它是后加加来的嘛.它现在的值是5,参加完运算后才自加一啊,而且它自加完后的结果是在参加下一次运算时才生效.还有什么疑问吗???

招远市19158506450: C语言的几个问题,大家帮忙
茅胥奥力: 算法就是解决问题的方法,算法应该具有5个特点1.有穷性---也就是说应该包含有限个步骤.2.确定性----算法中每条指令必须有确切的含义,不能有二义性,对于相同的输入必须得出相同的执行结果.3.可行性,算法中指定的操作都可以通过已经实现的基本运算执行有限次后实现.4.有零个或多个输入.5.有1个或多个输出.

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网