A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© yongwei 中级黑马   /  2015-7-18 21:47  /  949 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

我定义了一个函数但是好像是调用失败了,求大神来看看
#include<stdio.h>

void swap(int*,int*);

int main(void){

    int x,y;

    printf("please type x\n");

    scanf("%d",&x);

    printf("please type y\n");

    scanf("%d",&y);

    printf("x is %d,and y is %d\n",x,y);

    swap(&x, &y);

    printf("now x is %d,y is %d\n",x,y);

}

void swap(int *a,int *b)

{

    int temp;

    temp=*a;

    *a=*b;

    *b=temp;

}
[/code]
程序到swap(&x,&y )就断了
还有本来我不想用两个scanf()的,但是我要是scanf("%d,%d",&x,&y)就只能输入x, 输入完x回车后程序直接执行下一行

2 个回复

倒序浏览
别回车,输入逗号就ok了
回复 使用道具 举报
不回车 输入逗号就可以了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马