我試圖用gcc編譯一段代碼,創建一個隨機整數的串列,并對其進行排序。但我得到了這些錯誤 :
main.c:8:1: error: expected '; ', ',' or ')' before '{' token
8 | {
| ^
tri.c:8:1: error: expected ';', ',' or ')' before '{' token
8 | {
| ^
我的第一個檔案main.c包含 :
#include <stdio.h>
#include <stdlib.h>
#include "tri.h"
#include "nexe.h"
int main(void)
{
int *T;
int n、d、k。
char e;
do
{
Saisir_n1(n);
trait()。
T=CreaTablD(n)。
AffichageD(T,n)。
do。
{
printf("
在插入(1)和選擇(2)之間選擇三角形:")。
scanf("%d"/span>,&d)。
}while(d!=1 && d!=2) 。
do
{
printf("
選擇一個三角形順序的décroissant(d)和一個三角形順序的c):")。
scanf("%c"/span>, &e);
}while(e!='c' && e!='d') 。
trait()。
if (d==1)
Tri_Insertion(T,n,e)。
else[/span
Tri_Selection(T,n,e)。
AffichageD(T,n)。
free(T)。
do
{
printf("
你會重新啟動嗎?
Oui(1) Non(0) : ")。
scanf("%d"/span>&k)。
}while(k!=1 && k!=0)。
}while(k==1)。
return(0)。
而我的第二個檔案tri.c包含:
#include <stdio.h>
#include <stdlib.h>
#include "附件.h"
void Tri_Insertion(int *T。int n, char choix)
{
int cle,j;
if (choix!='c'/span> && choix!='d'/span>)
{
printf("
選擇引數時出現錯誤
")。)
return;
}
for (int i=1; i<n; i )
{
cle=*(T i)。
j=i-1
if (choix=='c'/span>)
{
while (j>0 && *(T j)>cle)
{
*(T j 1)=*(T i)。
j--;
}
}
else[/span
{
while (j>0 && *(T j)<cle)
{
*(T j 1)=*(T i)。
j--;
}
}
*(T j 1)=cle;
}
}
void Tri_Selection(int *T, int n, char choix)
{
int ie,e;
if (choix!='c'/span> && choix!='d'/span>)
{
printf("
選擇引數時出現錯誤
")。)
return;
}
if (choix=='c'/span>)
{
for (int i=0; i<n; i )
{
PlusPetitD(T,ie,e,0, n);
if (ie! =i)
{
permutationD(T i,T ie)。
}
}
}
else
{
for (int i=0; i<n; i )
{
PlusGrandD(T,ie,e,0, n);
if (ie! =i)
{
permutationD(T i,T ie)。
}
}
}
}
annexe.c是一個我非常確定沒有問題的檔案,因為它與其他檔案一起作業。 我檢查了所有的"}"和"{",所有的";",沒有一個丟失。
謝謝你的幫助。
uj5u.com熱心網友回復:
幾乎可以肯定是在你的Tri_Insertion()函式中--你有以下未結束的行,這可能是一個編譯器錯誤(它似乎是在你的tri.c檔案的第8行:
j=i-1
if (choix=='c'/span>)
這應該是:
j=i-1;
if (choix=='c'/span>)
uj5u.com熱心網友回復:
你的第二個檔案叫做tri.c , 但在main中你把它作為頭檔案#include "tri.h" 。這是正確的嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/306944.html
標籤:
上一篇:如何從一個字串中獲取某些東西
