第1个回答 2012-01-08
void FnNCopy(const char*ch,int m,char ch2)
{
int n=m-1;
for(int i=0;ch[n];i++,n++)
ch2[i]=ch[n];
ch2[i]='\0';
}
直接在main函数中调用就行了,C++和C都能编译.ch为要复制的字符串,m为要复制的第几个字符,注意是第几个字符,不是下标如果是按下标的话,把int n=m-1;改为n=m;
ch2为被复制到的目标字符串.注意ch2一定要足够大.
第2个回答 2012-01-08
#include <stdio.h>
#include <string.h>
char * my_copy( char *str , int m )
{
if ( m > strlen(str) ) return NULL ;
return str+m-1 ;
}
int main()
{
int m=0;
char str[81],*p=NULL;
printf("input a string:" );
gets( str );
printf("input position numner:" );
scanf("%d",&m );
p=my_copy( str , m );
printf("the result :\n");
printf("%s\n" , p );
return 0;
}
第3个回答 2012-01-10
#include<stdio.h>
#include<string.h>
void str_copy(char *A,char *B,int m)
{
B+=m-1;
strcpy(A,B);
}
int main()
{
char B[]="abcdefg",A[10];
int m=3;
str_copy(A,B,m);
puts(A);
return 0;
}
第4个回答 2012-01-08
用什么 语言??
第5个回答 2012-01-08
void FnNCopy(const char*ch,int m,char ch2)
{
int n=m-1;
for(int i=0;ch[n];i++,n++)
ch2[i]=ch[n];
ch2[i]='\0';
}
直接在main函数中调用就行了,C++和C都能编译.ch为要复制的字符串,m为要复制的第几个字符,注意是第几个字符,不是下标如果是按下标的话,把int n=m-1;改为n=m;
ch2为被复制到的目标字符串.注意ch2一定要足够大.
第6个回答 2012-01-08
#include <stdio.h>
#include <string.h>
char * my_copy( char *str , int m )
{
if ( m > strlen(str) ) return NULL ;
return str+m-1 ;
}
int main()
{
int m=0;
char str[81],*p=NULL;
printf("input a string:" );
gets( str );
printf("input position numner:" );
scanf("%d",&m );
p=my_copy( str , m );
printf("the result :\n");
printf("%s\n" , p );
return 0;
}
第7个回答 2012-01-10
#include<stdio.h>
#include<string.h>
void str_copy(char *A,char *B,int m)
{
B+=m-1;
strcpy(A,B);
}
int main()
{
char B[]="abcdefg",A[10];
int m=3;
str_copy(A,B,m);
puts(A);
return 0;
}
第8个回答 2012-01-08
用什么 语言??