Ik krijg de onderstaande foutmelding, wat is de std=c99/std=gnu99-modus?
broncode:
#include <stdio.h>
void funct(int[5]);
int main()
{
int Arr[5]={1,2,3,4,5};
funct(Arr);
for(int j=0;j<5;j++)
printf("%d",Arr[j]);
}
void funct(int p[5]) {
int i,j;
for(i=6,j=0;i<11;i++,j++)
p[j]=i;
}
Error Message:
hello.c: In function ‘main’:
hello.c:11:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
for(int j=0;j<5;j++)
^
hello.c:11:2: note: use option -std=c99 or -std=gnu99 to compile your code`
Antwoord 1, autoriteit 100%
Dit gebeurt omdat het declareren van variabelen binnen een for-lus pas geldig was C tot C99 (wat de standaard is van C gepubliceerd in 1999), je kunt ofwel je teller declareren buiten de for zoals aangegeven door anderen, of de -std gebruiken =c99-vlag om de compiler expliciet te vertellen dat u deze standaard gebruikt en dat deze deze als zodanig moet interpreteren.
Antwoord 2, autoriteit 16%
Je moet de variabele j declareren die wordt gebruikt voor de eerste for-lus vóór de lus.
int j;
for(j=0;j<5;j++)
printf("%d",Arr[j]);
Antwoord 3, autoriteit 2%
Eenvoudigste oplossing door “Prof. Dr. Michael Helbig” . het zal je modus naar c99 schakelen, zodat je niet elke keer een vlag hoeft toe te voegen in het make-bestand
http://www.bigdev .de/2014/10/eclipse-cc-for-loop-initial.html?showComment=1447925473870#c6845437481920903532
Oplossing: gebruik de optie -std = C99 voor uw compiler! Ga naar: project & GT; Eigenschappen & GT; C / C++ BUILS & GT; Instellingen & GT; Gereedschapsinstellingen & GT; GCC C COMPILER & GT; Dialect & gt; Taalstandaard: kies “ISO C99”
Antwoord 4
Dit is Werkcode
#include <stdio.h>
void funct(int[5]);
int main()
{
int Arr[5]={1,2,3,4,5};
int j = 0;
funct(Arr);
for(j=0;j<5;j++)
printf("%d",Arr[j]);
}
void funct(int p[5]){
int i,j;
for(i=6,j=0;i<11;i++,j++)
p[j]=i;
}