打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用例
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

 
错误
#include <stdio.h>
#include <string.h>
 
char *my(char *f1, int n)
{
    int len=strlen(f1);
    char temp[15];
     char *p1;
    strcpy(temp,f1+len-n);
    strcpy(temp+n,f1);
    temp[len]='\0';
    p1=temp;
    return p1;
 
}
 
int main()
{
    char *p="5466565655";
    char *p1;
 
    p1=my(p,3);
----------------------
    printf("%s\n",p1); -------------这样就不能输出?
----------------------
    for(。。。。)
   {
        printf("%c",*p);----------这样可以输出?
    }
 
-----------------------
    return 0;
 
 
}

 

 
正确

 

 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char *my(char *f1, int n)
{
    int len=strlen(f1);
    char* p1 = (char*)malloc(15 * sizeof(char));
 
    strcpy(p1, f1 + len - n);
    strcpy(p1 + n, f1);
    p1[len] = '\0';
 
    return p1;
}
 
int main(int argc, char* argv[])
{
    char *p="5466565655";
    char *p1;
 
    p1 = my(p, 3);
    printf("%s\n", p1);
        printf("%c", *p1);
 
    free(p1);
    return 0;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
编程实现字符串长度测量
文件校验之Adler32算法的实现
C语言练习题精选
数据结构与算法分析(C)1.4
指针数组和数组指针
USACO/runround
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服