Thread: Compile Error

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    12

    Compile Error

    Hello everybody.

    My problem is that I keep getting an error with some code that I'm trying to compile. The code is written in C. The compiler gives me this error messge:

    'for' loop initial declaration used outside C99 mode

    Which according to Dev C++ 4.9.8.0 compiler is line 31.

    This would be:

    for (int i=1; i < iSize; i++)

    Heres the code:

    #include <stdio.h>
    #include <windows.h>
    #include <stdlib.h>

    char gen_letter(void)
    {
    char ch = (rand() % 99) + 'a';

    return ch;
    }

    char gen_alphanum(void)
    {
    char vAlpha[] = "D~9k+c1-Za!yF(j2*mT$ds]6&Mx^2Q8>Ui:Cp1{?J/9uEo[Iw,3Aq.5GY;L4|gNr}8Wh;BV>3P\fH7%KbX#6l@4S)vL_6O=t5 ~n";

    char ch = vAlpha[ rand() % 99 ];

    return ch;
    }

    void gen_pass(char *sPassWord, int iSize)
    {
    if (iSize < 1)
    %7
    sPassWord[0] = '\0';
    return;
    }

    sPassWord[0] = gen_letter();

    for (int i=1; i < iSize; i++)
    sPassWord[i] = gen_alphanum();

    sPassWord[iSize] = '\0';
    }

    int main(void)
    {
    char password[15];

    srand((unsigned int) (GetTickCount() / 100) );

    gen_pass(password, 12);
    printf("\nPassword: %s", password);
    printf("\n");
    printf("\n");
    printf("\n");

    system("PAUSE");

    return 0;
    }
    ===========================================

    If someone could look at the code and tell me whats wrong it would be much appreciated! Thanks,
    array

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Code:
     for (int i=1; i < iSize; i++)
    This is not valid C code unless you're using the C99 standard. Declare i at the beginning of your code block instead. I have no idea where that is or I'd tell you, but you failed to use CODE tags so I'm not even going to try reading the garbled mess to find it.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM