第8周筆記7-間隔提取字符串字符

間隔提取字符串字符

        將字符數組str1種下標爲偶數的元素賦值給另外一個字符數組str2。

/*
將字符數組str1種下標爲偶數的元素賦值給另外一個字符數組str2。
*/
#include<stdio.h>
#define N 100
int main(){
	char str1[N],str2[N];
	scanf("%s",str1);
	char *p=str1,*q=str2;
	int len=0;
	while(*p!='\0'){ len++; p++;}
	p=str1;
	while(p<=str1+len){
		*q=*p;
		p++;p++;
		q++;
    }
	*q='\0';
	printf("%s",str2);
	return 0;
} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章