linux 操作 day 7

1、下列对 C 语言字符数组的描述中错误的是 ( ) 

A. 字符数组可以存放字符串

B. 字符数组中的字符串可以整体输入、输出

C. 不可以用关系运算符对字符数组中的字符串进行比较

D. 可以在赋值语句中通过赋值运算符 "=" 对字符数组整体赋值

2、下列描述中不正确的是( )

A.字符型数组中可以存放字符串

B.可以对字符型数组进行整体输入、输出        //strcpy(拷贝);strcat(增加字符)

C.可以对整型数组进行整体输入、输出      

D.不能在赋值语句中通过赋值运算符"="对字符型数组进行整体赋值

3、下列代码片段执行的结果是:

char szTest[] = "ABCDEF";

strncpy(szTest, szTest, 4);  //strncpy功能:将后面个数组确定拷贝多少个到目的空间中;

printf("%s", szTest);

A、ABCD            B. ABCDE          C. ABCDEF                 D. 以上都不对

4、以下对字符数组test 赋值方式错误的是( )。 

A. char test[10]; strcpy(test, "test");

B. char test[10]; test="test";

C. char test[]={'t', 'e', 's', 't’};

D. char test[10]={'t', 'e', 's', ‘t’};

5、以下语句不能正确赋值的是( ) 

A. char *s = "China";

B. char s3[20] = "China";

C. char s2[]={'C', 'h', 'i', 'n', 'a'};

D. char s1[10]; s1="China";

6、以下程序运行后输出结果是( ) 

main()

{

    char ch[2][5] = {"693", "825"}, p[2][5];

ch
69300

8

2500
p

    int i, j, s = 0;

    for(i=0;i<2;i++) strcpy(ch,p);        //使p数组两行字符串与ch相同

    for(i=0;i<2;i++){

            for(j=0;p[i][j]>='0' && p[i][j]<='9';j+=2)

                  int s    ;   

                 s=10*s+p[i][j]-'0';   6 3 8 5

           }

        printf("%d\n", s);

}

A、6385          B. 33          C. 693825                  D. 22

7、为了比较两个字符串s1和s2是否相等,应当使用( ) 

A. if(s1 = s2)                                          B. if(s1==s2)

C. if(strcmp(&s1, &s2)==0)                 D. if(strcmp(s1, s2)==0)              //strcmp中两数组相

                                                                                                                //等时,返回值是0

 

8、编写一个程序。输入一个字符串,将其逆序后输出?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
	char a[100];
	printf("请输入一串字符:");
	scanf("%s",a);
	int i=0, j;
	j=strlen(a)-1;
	char t;
	while(i<j){
		t=a[i], a[i]=a[j],a[j]=t;
		i++,  j--;
	}printf("%s\n",a);
	return 0;
}

9、编写一个程序。负责将一个字符串拷贝到另一个字符串,不调用 C++/C 的字符串库函数。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
	char a[]="568977222";
	char b[]="666666";
	int i ,j;
	for(i=strlen(a)-1;i>0;i--){
		a[i]=0;	
	}
	while(b[j]!='\0'){
		a[i]=b[j];
		i++  ,j++;
	}
	a[i]=0;
	printf("%s",a);
	return 0;
}

10、编写一个程序。不使用字符串连接函数strcat,实现两个字符串的链接

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
	char a[1000];
	char b[1000];
	printf("请输第一串字符: ");
	scanf("%s",a);
	printf("请输入第二串字符:");
	scanf("%s",b);
	int i=strlen(a);
	for(int j=0;j<=strlen(b)-1;j++){
		a[i]=b[j];
		i++;
	}
	printf("%s\n",a);
	return 0;
}

 

11、编写一个程序。请实现输入一个字符串,这个字符串字符串包含一个或多个数字,把这些数字字符转换为整数,如果字符串参数包含了非数字字符,置零,不必担心算数溢出。

输入:123abc456

输出:printf(“%d\n” , num);  num=123000456

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
	char a[1000];
	printf("please enter a string characters:");
	scanf("%s",a);
	int i;
	for(i=0;i<strlen(a)-1;i++){
		if(a[i]<='z'&&a[i]>='A'){
			a[i]=0;
		}
	}
	printf("%s\n",a);
	return 0;
}

12、编写一个程序。实现输入N个字符串,输出这N个字符串中的最大字符串和最长字符串,可以调用字符串处理函数。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值