wont compile --> dev-C++

Livzz

New Member
hey,
i got dev-C++ (ver 4.9.9.2), which is a really good program... but it wont compile the following code... which i know is good. It comes up with the message:

'for' loop initial declaration used outside C99 mode


for (int i = 0; i < length; i++)
{
printf("%c %c \n", argv[1] ,rotate(argv[1]));
}


help?!
cheers,
Paul
 
Is "length" defined in any above code? For "rotate", I believe there are three parameters and each parameter needs to be an iterator (i.e. a vector)...
 
Last edited:
Its not my code, it was provided by the lecturer so everything works, and i can compile it with Cygwin but not Dev-C++

Heres the whole code:


static char rotate(char c)
{
/* Check if c is lower-case or not */
if (islower(c))
{
/* The ciphered character is ROT positions beyond c,
allowing for wrap-around
*/
return ('a' + (c - 'a' + ROT) % 26);
}
else
{
return ('a' + (c - 'a' + ROT) %26);
}
}

int main(int argc, char *argv[])
{
/* Exit with an error if the the number of arguments (including
the name of the executable) is not precisely 2
*/
if(argc != 2)
{
fprintf(stderr, "%s: program expected 1 argument, but instead received %d\n", argv[0], argc-1);
exit(EXIT_FAILURE);
}
else
{
/* Calculate the length of the first argument */
int length = strlen(argv[1]);
/* Loop for every character in the text */
for (int i = 0; i < length; i++)
{
/* Determine and print the ciphered character */
printf("%c %c \n", argv[1] ,rotate(argv[1]));
}
/* Print one final new-line character */
printf("\n");
/* Exit indicating success */
exit(EXIT_SUCCESS);
}
return 0;
}
 
sorry - missed the first few lines:

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

/* Compile this program as:
gcc -std=c99 -Wall -Werror -pedantic -o rot rot.c
*/

#define ROT 5
 
well, all I can do is compile in in Visual Studio .NET 2003 or VS 2005.. and in both cases it compiled correctly...

I believe in the c99 standard you can have the declaration of i in the for loop argument.

It might be that the init of i inside the for loop needs to occur outside of the loop or you need to change the settings so that std=c99 (not sure where that setting is located..)
 
ok cheers, i'll get hold of the lecturer when i can...

whats visual studio like? you reccommend it for a student?

edit:
i tried having "int i=0;" outside the loop, and it compiled!
cheers again!
 
Last edited:
I have bloodshed Dev-C++ 4.9.9.2 aswell, i just copied and poasted your code in and it compiled fine for me.... no erors at all. You sure your compiling into C++ source file not C#... simple but a common mistake

dragon
 
ok cheers, i'll get hold of the lecturer when i can...

whats visual studio like? you reccommend it for a student?

edit:
i tried having "int i=0;" outside the loop, and it compiled!
cheers again!


Not a problem...glad it worked!
 
I have bloodshed Dev-C++ 4.9.9.2 aswell, i just copied and poasted your code in and it compiled fine for me.... no erors at all. You sure your compiling into C++ source file not C#... simple but a common mistake

where can i change that? and also, how do i get it to display the line numbers on the side?

the course i'm doing is for the ISO-C99 standard, is that the same as C++?
 
where can i change that? and also, how do i get it to display the line numbers on the side?

the course i'm doing is for the ISO-C99 standard, is that the same as C++?
Well, open up a new instance of Dev-C++ and go to file and New Source File, copy in all the code as i did and when you hit F9 to compile for the first time, it will come up with a save dialog to ask you where to save the source file for it, by default it may be set to something like C or C# and not C++, just double check its set to "C++ Source File" save it and it should then proceed to compile.

Thats all i did and it works fine, ive got the compiled .exe and the C++ source file if you want me to email them to you? drop me an email to dragon2309{at}gmail.com if you do.

dragon
 
i want it to be in the ISO-C99 standard, i dont know if thats C, C++, C# or any other variation....
i did copy it just as you did with a fresh source file, and saved it as a ".c" and as a C++ source file, and both times it still came up with the error.
 
Back
Top