标题:strcpy在gcc下的兼容问题,提示:“passing argument 1 of ‘strcpy’ from ...
只看楼主
静夜思
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:济南的冬天
等 级:管理员
威 望:11
帖 子:8842
专家分:2567
注 册:2004-3-25
结帖率:100%
已结贴  问题点数:100 回复次数:3 
strcpy在gcc下的兼容问题,提示:“passing argument 1 of ‘strcpy’ from incompatible pointer ty
下面这段代码,用cmake运行正常,用gcc运行出错,请诸位高手告知如何才能跟gcc兼容:
程序代码:
/**

 * 【程序79】

 * 题目:字符串排序。

 */

#include <stdio.h>
#include <string.h>

char swap(p1, p2)
        char *p1, *p2;
{
    char *p[200];
    strcpy(p, p1);
    strcpy(p1, p2);
    strcpy(p2, p);
}

int main() {
    char *str1[200], *str2[200], *str3[200];
    char swap();
    printf("please input three strings\n");
    scanf("%s", str1);
    scanf("%s", str2);
    scanf("%s", str3);
    if (strcmp(str1, str2) > 0) {
        swap(str1, str2);
    }
    if (strcmp(str1, str3) > 0) {
        swap(str1, str3);
    }
    if (strcmp(str2, str3) > 0) {
        swap(str2, str3);
    }
    printf("after being sorted\n");
    printf("%s\n%s\n%s\n", str1, str2, str3);

    return 0;
}

在线调试地址:https://www.bccn.net/run/95944
搜索更多相关主题的帖子: printf gcc strcpy char 兼容 
2019-10-23 16:58
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:100 
程序代码:
void swap( char* p1, char* p2)
{
    char p[200];
    strcpy(p, p1);
    strcpy(p1, p2);
    strcpy(p2, p);
}

int main( void )
{
    char str1[200], str2[200], str3[200];
    printf("please input three strings\n");
    scanf("%s", str1);
    scanf("%s", str2);
    scanf("%s", str3);
    if (strcmp(str1, str2) > 0) {
        swap(str1, str2);
    }
    if (strcmp(str1, str3) > 0) {
        swap(str1, str3);
    }
    if (strcmp(str2, str3) > 0) {
        swap(str2, str3);
    }
    printf("after being sorted\n");
    printf("%s\n%s\n%s\n", str1, str2, str3);
    return 0;
}
2019-10-23 17:15
静夜思
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:济南的冬天
等 级:管理员
威 望:11
帖 子:8842
专家分:2567
注 册:2004-3-25
得分:0 
回复 2楼 rjsp
非常感谢,已编译通过

畅所欲言
2019-10-23 17:25
forever74
Rank: 12Rank: 12Rank: 12
来 自:CC
等 级:贵宾
威 望:49
帖 子:1636
专家分:3940
注 册:2007-12-27
得分:0 
这个,
我有点胃疼。
端起咖啡,45度角仰望K&R星座......

对宇宙最严谨的描述应该就是宇宙其实是不严谨的
2019-10-23 17:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-497400-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.735434 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved