程序设计题
编写程序,将字符串 s1 中的全部字符拷贝到字符数组 s2 中,不要用 strcpy 函数;拷贝时,’\0’也要拷贝过去,’\0’后面的字符不拷贝。
#include<stdio.h>
int mian() {
char s1[10], s2[10];
int i=0;
gets(s1);
while(s1[i] != '\0') {
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
puts(s2);
#include <stdio.h> #include <string.h> #include <stdbool.h> #include <math.h> #include <stdlib.h> #include <time.h> char s1[105]; char s2[195]; int main(){ scanf("%s",s1); scanf("%s",s2); int length=strlen(s1); int length_2=strlen(s2); for(int i=0;i<length;i++){ s2[length_2+i]=s1[i]; if(s1[i]=='0'){ break; } } puts(s2); return 0; }
/*程序设计题 编写程序,将字符串 s1 中的全部字符拷贝到字符数组 s2 中,不要用 strcpy 函数;拷贝时, ’\0’也要拷贝过去,’\0’后面的字符不拷贝。*/ #include<stdio.h> char *my_strcpy(char *dest,const char *src){ char *p = dest; while(*src){ *dest = *src; dest++; src++; } *dest = '\0'; return p; } int main(){ char s1[20] = "123"; char s2[20] = "a"; printf("%s",my_strcpy(s1,s2)); return 0; }
1
char* strcpy(char *s1,char*s2){
int i=0;j=0;
for(;s1[j]!='\0';j++){
s2[i++]=s1[j];
s2[i]='\0';
return s2;
#include<stdio.h> int main() { char s1[] = "hello world!"; char s2[20]; int i = 0; while (s1[i] != '\0') { s2[i] = s1[i]; i++; } s2[i] = '\0'; i =0; while (s2[i] != '\0') { printf("%c", s2[i]); i++; } return 0; }
while(*s1!='\0')
{
s2[i++] = *(s1++);
s2[i] = *s1;
k
111
#include<stdio.h> void _strcpy(char *target,char *src); int main(){ char s1[256],s2[256]; scanf("%s",s1); scanf("%s",s2); _strcpy(s2,s1); printf("%s",s2); } void _strcpy(char *target,char *src){ int i=0,j=0; while(src[i]!='\0'){ target[j++]=src[i++]; } target[j]='\0'; }
#include <stdio.h>
void copyString(const char *s1, char *s2) {
while (*s1 != '\0') { *s2 = *s1; // 将当前字符从 s1 拷贝到 s2 s1++; // 移动 s1 指针到下一个字符 s2++; // 移动 s2 指针到下一个位置 } *s2 = '\0'; // 确保在 s2 的末尾添加字符串结束符 }
int main() { char s1[] = "Hello, World!"; char s2[100];
copyString(s1, s2);
printf("Copied String: %s\n", s2); return 0; }
#include 1分 int main( ) 1分 { char s1[20],s2[20]; 1分 int i; 1分 scanf("%s",s1); 1分 for(i=0;s1[i]!='\0';i++) 1分 s2[i]=s1[i]; 1分 s2[i]='\0'; 1分 printf("%s\n",s2); 1分 return 0; 1分 }
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main(void) { char s1[50], s2[50]; int i = 0; while (s1[i] != '\0') { s2[i] = s1[i]; i++; } s2[i + 1] = '\0'; printf("%s\n", s2); return 0; }
Nature 回复 Nature: #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main(void) { char s1[50], s2[50]; int i = 0; for (i; i < 50; i++) { if (s1[i] == '\0') { s2[i + 1] = '\0'; break; } s2[i] = s1[i]; } printf("%s\n", s2); return 0; }
int main( )
char s1[20],s2[20];
int i;
scanf("%s",s1);
for(i=0;s1[i]!='\0';i++)
s2[i]=s1[i];
printf("%s\n",s2);
return 0;
#include <stdio.h> void copyString(const char *s1, char *s2) { while (*s1 != '\0') { *s2 = *s1; // 将当前字符从 s1 拷贝到 s2 s1++; // 移动 s1 指针到下一个字符 s2++; // 移动 s2 指针到下一个位置 } *s2 = '\0'; // 确保在 s2 的末尾添加字符串结束符 } int main() { char s1[] = "Hello, World!"; char s2[100]; copyString(s1, s2); printf("Copied String: %s\n", s2); return 0; }
int main() { char s1[20],s2[20]; int i; char c; for(i = 0;s1[i]!='\0';i++) s2[i] = s1[i]; s2[i] = '\0'; printf("%s\n",s2);
OK
#define V 10 int main() { char s1[]="helloWorl", s2[V + 1]; for (int i = 0; i < V; i++) { if (s1[i] == '\0') { s2[i] = s1[i]; break; } s2[i] = s1[i]; } for (int i = 0; i < V+1; i++) printf("%c", s2[i]); return 0; }
oh~yeah
int main() { char s1[20], s2[20]; int i;
scanf("%s", s1);
for (i = 0; s1[i] != '\0'; i++) { s2[i] = s1[i]; } s2[i] = '\0'; printf("%s\n", s2);
return 0; }
//编写程序,将字符串 s1 中的全部字符拷贝到字符数组 s2 中,不要用 strcpy 函数;拷贝时,’\0’也要拷贝过去,’\0’后面的字符不拷贝。 #include <stdio.h> int main() { char s1[20] = "hello world" ; char s2[20] = { 0 }; int i = 0; while (s1[i]!='\0') { s2[i] = s1[i]; i++; } printf("%s ", s2); }
int main()
char s1[21],s2[21];
int main(){ char s1[20],s2[20]; int i; scanf("%s",s1); for(i=0;s1[i]!='\0';i++){ s2[i]=s1[i]; } s2[i]='\0'; printf("%s\n",s2); return 0; }
#include <stdio.h> #include <stdlib.h>
int main() { int i=0; char s1[20],s2[20]; scanf("%s",s1); for(i=0;s1[i]!='\0';i++) s2[i]=s1[i]; s2[i]='\0'; printf("%s\n",s2); return 0; }
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> int main() { char a[100]; char b[100]; scanf("%s",a); for(int i=0;i<strlen(a);i++) { b[i]=a[i]; } printf("%s\n",b); return 0; }
void str_cpy(char *s1, char *s2) { int i = 0; do { *(s2 + i) = *(s1 + i); } while (*(s1 + i++)); }
int main(){
#include <stdio.h> int main(){ char s1[100],s2[100]; int i; scanf("%s",s1); for(i = 0;s1[i] != '\0';i++){ s2[i] = s1[i]; } s2[i]='\0'; printf("%s\n%s",s1,s2); return 0; }
#include int main(){ char from[10]="abcdef",to[10]="ABCDEFG"; int i=0; while(from[i]!='\0'){ to[i]=from[i]; i++; } to[i]='\0'; printf("%s",to); }
#include<stdio.h> int main() { char s1[10] = "asdasdasf"; char s2[10]; int i = 0; while(s1[i] != '\0') { s2[i]=s1[i]; i++; } s2[i]=s1[i]; printf("%s\n",s2); return 0; }
#include <stdio.h> void main() { char s1[10]="abcdefgh"; char s2[10]="\0"; for(int i=0;i<10;i++) if(s1[i]!='\0') s2[i]=s1[i]; else{ s2[i]='\0'; break; } printf("%s\n",s2); }
int main() { char root[]="carrot"; char aim[100] ; int i; for( i = 0;i<sizeof(root)+1;i++) { aim[i]=root[i];
};
printf("%s",aim); }
int main() { char s1[100],s2[100]; for(int i=0;i<100;i++) { s2[i]=s1[i]; if(s1[i]=='\0') break; } }
#define LEN 30
int length(char *b) //获取实际长度 { int k=0; int i=0; for(i=0;i<LEN;i++) { if(b[i]!='\0') k+=1; } return k; }
void show(char *a) { int len = length(a); int i; for(i=0; i<len;i++) { printf("%c",a[i]); } }
char *copy(char *a, char *b) { int len = length(b); int i; // char *k=a; int j=1; for(i=0;i<len;i++) { if(b[i]=='\0') { a[i]=b[i]; break; }else{ a[i]=b[i]; } } return a; } int main() { //将B复制给a char a[LEN] = {"abcde"}; char b[LEN] = {"zhongguo\0wansui"}; copy(a,b); show(a); }
#include <stdio.h> #define LEN 30 int lenth(char *b) { //返回字符串有效位数函数 int k = 0; for (int i = 0; i < LEN; ++i) { if (b[i] != '\0') k += 1; } return k; } void show(char *a) { //输出字符串函数 int len = lenth(a); for (int i = 0; i < len; ++i) { printf("%c", a[i]); } } char *copy(char *a, char *b) { //复制函数:把a字符串的内容复制给b。 int len = lenth(b); char *k = a; int j = 1; for (int i = 0; i <= len; ++i) { if (b[i] == '\0') { a[i] = b[i]; break; } else a[i] = b[i]; } return k; } int main() { char a[LEN] = {"abcde"}; char b[LEN] = {"zhongguo\0wansui"}; copy(a, b); show(a); return 0; }
int main(){ char a[] = "abc"; char b[10]; int i; for(i = 0; a[i] != '\0'; ++i) b[i] = a[i]; b[i] = '\0'; for(i = 0; b[i] != '\0'; ++i) printf("%c",b[i]); return 0; }
#include <stdio.h> int main(){ char s1[20]="abcdefg",s2[20]; for (int i = 0; i < sizeof(s1)+1; i++) { s2[i]=s1[i]; } printf_s("%s",s2); return 0; };
Void strcpy_my(char *s1, char *s2) { While((*s2 = *s1) != ‘\0’) { S2++; S1++; } *s2 = ‘/0’;
#include<stdio.h> #include<math.h>
int main(){ char a[] = "abcde"; char b[10]; int i; for(i = 0; a[i] != '\0'; ++i) b[i] = a[i]; b[i] = '\0'; for(i = 0; b[i] != '\0'; ++i) printf("%c",b[i]); return 0; }
#define _CRT_SECURE_NO_WARNINGS #pragma warning(disable:6031) #include<stdio.h> #include<string.h> #include<assert.h>//const修饰不许home被修改 char* my_strcpy(char* end, const char* home) { assert(home != NULL); assert(end != NULL);//断言 char* ret = end;//留下起始地址 while (*end++ = *home++) { ;//ascii码值判断,直到\0copy完成,\0为假循环停止 } return ret;//返回起始地址 } int main() { char arr1[] = "xxxxxxxx"; char arr2[] = "hello"; //strcpy(arr1, arr2); //printf("%s\n", arr2); printf("%s\n", my_strcpy(arr1, arr2)); return 0; }
#include<stdio.h> int main() { char str1[20],str2[20]; int i=0,j=0; gets(str1); while(str1[i]!='\0') { str2[j]=str1[i]; j++; i++; } str2[j]='\0'; printf("%s",str2); return 0; }
int main() { int i = 0; char s1[20], s2[20]; scanf("%s", s1); while (s1[i] != '\0') { s2[i] = s1[i]; i++; } s2[i] = '\0'; for (int x = 0; s2[x] != '\0'; x++) { printf("%c", s2[x]); } return 0; }
#include <stdio.h> void sstrcpy(char *s2, char *s1); void main(){ char s1[] = "3461289461", s2[30]; sstrcpy(s2, s1); puts(s2); }
void sstrcpy(char *s2, char *s1){ int i = 0; while (s1[i] != '\0'){ s2[i] = s1[i]; i++; } s2[i] = '\0'; }
#include <math.h>
int main ( )
for(i=0;s1[i]!=0;i++)
printf("%s",s2);
#include<stdio.h> int main(){ char s1[10],s2[10]; int i; printf("please inout string s1:"); scanf("%s",s1); for(i=0;s1[i]!='\0';i++){ s2[i]=s1[i]; } s2[i]='\0'; printf("%s\n",s2); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { char s1[20] = ""; scanf("%s", s1); char s2[20] = ""; int length = sizeof(s1) / sizeof(s1[0]); for (int i = 0; i < length; i++) { if(s1[i]!='/0') s2[i] = s1[i]; else { s2[i] = s1[i]; break; } } for (int j = 0; j < length; j++) { printf("%c", s2[j]); } return 0; }
#include void main(){ char a[], b[]; int i; gets(a); for(i=0;a[i]!='0',i++) b[i]=a[i]; b[i]='0'; puts(b); )
#include<stdio.h> int main(){ char s1[10],s2[10]; gets(s1); int i=0; while(s1[i]!='\0'){ s2[i]=s1[i]; i++; } s2[i]='\0'; puts(s2); }
include <stdio.h> int main() { int char s1[],s2[]; scanf("%s", s1); int i; for(i=0;s1[i]!='/0';i++) s2[i] = s1[i]; s2[i] = '/0'; return 0; }
int main() { int i=0; char c,s1[100],s2[100]; gets(s2); c=s2[i]; while(c!='\0') { s1[i]=c; i++; c=s2[i]; } s1[i]=c; puts(s1); return 0; }
#include<stdio.h> int main(){ char str1[]="China"; char str2[10]; int i; for(i=0;str1[i]!='\0';i++){ str2[i]=str1[i]; } str2[i]=str1[i]; printf("%s\n",str2); return 0;
int main() { char s1[80],s2[80]; int i=0; gets(s1); while(s1[i]!='\0') { s2[i]=s1[i]; i++; } s2[i]='\0'; return 0; }
#include int main() { void f(char s3[],char s4[]); char s1[100],s2[100]; scanf("%s%s",s1,s2); f(s1,s2); printf("%s",s2); } void f(char s3[],char s4[]){ int i; for(i=0;s3[i]!='\0';i++) s4[i]=s3[i]; s4[i]='\0'; }
#include<stdio...
用户登录可进行刷题及查看答案
#include<stdio.h> 1分
int main( ) 1分
char s1[20],s2[20]; 1分
int i; 1分
scanf("%s",s1); 1分
for(i=0;s1[i]!='\0';i++) 1分
s2[i]=s1[i]; 1分
s2[i]='\0'; 1分
printf("%s\n",s2); 1分
return 0; 1分
登录后提交答案