Connor666 发表于 2022-4-6 17:49:41

大神怎么怎么编译不了,提示错也不定位在哪里??

#include <stdio.h>

void main()
{
        void exchange(int *q1 int *q2 int *q3)
        int a,b,c,*q1,*q2,*q3;

        scanf("%d %d %d",&a,&b,&c);
        p1 = &a;
        p2 = &b;
        p3 = &c;

        exchange(p1,p2,p3);

        printf("%d %d %d\n",a,b,c);
}

void exchange (int *q1,int *q2,int *q3)
{
        if(*q1 < *q2)
        {
                swap(q1,q2);
        }
        if(*q1 < *q3)
        {
                swap(q1,q3);
        }
        if(*q2 < *q3)
        {
                swap(q2,q3);
        }
}

void swap(int *pt1,int *pt2)
{
        int temp;
        temp = *pt1;
        *pt1 = *pt2;
        *pt2 = temp;
}

提示:
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(6) : error C2143: syntax error : missing ';' before 'type'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(9) : error C2065: 'p1' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(9) : warning C4047: '=' : 'int ' differs in levels of indirection from 'int *'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(10) : error C2065: 'p2' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(10) : warning C4047: '=' : 'int ' differs in levels of indirection from 'int *'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(11) : error C2065: 'p3' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(11) : warning C4047: '=' : 'int ' differs in levels of indirection from 'int *'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(13) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(13) : warning C4024: 'exchange' : different types for formal and actual parameter 1
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(13) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(13) : warning C4024: 'exchange' : different types for formal and actual parameter 2
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(13) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(13) : warning C4024: 'exchange' : different types for formal and actual parameter 3
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(22) : warning C4013: 'swap' undefined; assuming extern returning int
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\exchange\exchange.c(35) : error C2371: 'swap' : redefinition; different basic types
执行 cl.exe 时出错.

isdkz 发表于 2022-4-6 17:55:29

本帖最后由 isdkz 于 2022-4-6 17:58 编辑

#include <stdio.h>

void main()
{
      void exchange(int *q1, int *q2, int *q3);            // 这里少了逗号和分号
      int a,b,c,*p1,*p2,*p3;                                        // 这里把 p 打成了 q

      scanf("%d %d %d",&a,&b,&c);
      p1 = &a;                  
      p2 = &b;                     
      p3 = &c;                     

      exchange(p1,p2,p3);

      printf("%d %d %d\n",a,b,c);
}

void exchange (int *q1,int *q2,int *q3)
{
      if(*q1 < *q2)
      {
                swap(q1,q2);
      }
      if(*q1 < *q3)
      {
                swap(q1,q3);
      }
      if(*q2 < *q3)
      {
                swap(q2,q3);
      }
}

void swap(int *pt1,int *pt2)
{
      int temp;
      temp = *pt1;
      *pt1 = *pt2;
      *pt2 = temp;
}

Connor666 发表于 2022-5-5 17:06:48

isdkz 发表于 2022-4-6 17:55


好的 谢谢已解决。
页: [1]
查看完整版本: 大神怎么怎么编译不了,提示错也不定位在哪里??