Hello, I started learning C yesterday, I came here with lots of experience in python scripting. I created a script that uses a variable in a for-loop, that was defined before the loop its self. I get this error:

skilz.c: In function ‘main’:
skilz.c:16: error: ‘prog’ undeclared (first use in this function)
skilz.c:16: error: (Each undeclared identifier is reported only once
skilz.c:16: error: for each function it appears in.)

In python, A variable is passed through into a for-loop automatically.
I have clearly defined the "prog" variable, and the only explanation to the error that i can see, is that its not automatically passing that variable into the loop.
code:

#include <stdio.h>

int main()
{
    int loop;
    int times = 0;
    char porg[10]; //short for progress
    char dataDone[20];

//    for (loop = 10; loop == 10; loop++) { //should make char == "          "
//        prog[loop] = " ";               }

    for (loop = 100; loop == 100; loop++) {
        
        if (times == 10) {
            prog[(loop/10)] = "=";
            times = 0;   }
        
        dataDone[19] = "[%s][%d%]", prog, loop;
        times++;
        printf("Download in progress... %57s", dataDone);
        }
}

/*End result shoulf look something like this:
Download in progress....                                                        [====      ][40%]
*/

Any help would be appreciated
Thanks; The-IT

Edited 6 Years Ago by The-IT: n/a

I created a script that uses a variable in a for-loop, that was defined before the loop its self. I get this error:

skilz.c: In function ‘main’:
skilz.c:16: error: ‘prog’ undeclared (first use in this function)
skilz.c:16: error: (Each undeclared identifier is reported only once
skilz.c:16: error: for each function it appears in.)

In python, A variable is passed through into a for-loop automatically.
I have clearly defined the "prog" variable, and the only explanation to the error that i can see, is that its not automatically passing that variable into the loop.
code:

#include <stdio.h>

int main()
{
    int loop;
    int times = 0;
    char [B]porg[/B][10]; //short for progress
    char dataDone[20];

//    for (loop = 10; loop == 10; loop++) { //should make char == "          "
//        prog[loop] = " ";               }

    for (loop = 100; loop == 100; loop++) {
        
        if (times == 10) {
            prog[(loop/10)] = "=";
            times = 0;   }
        
        dataDone[19] = "[%s][%d%]", prog, loop;
        times++;
        printf("Download in progress... %57s", dataDone);
        }
}

/*End result shoulf look something like this:
Download in progress....                                                        [====      ][40%]
*/

I believe the compiler. :P

This article has been dead for over six months. Start a new discussion instead.