Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

printf undeclared

EsqulaxEsqulax Member Posts: 1
Hiya guys.. ive done some C and C++ in the (fairly distant) past, and decided to have another go.
i got a Library called "Allegro" and installed it, and im using Dev-C++

Ok.. so program to test Allegro version, using the allegro library:

[code]
#include
#include


int main()
{
allegro_init();
printf("allegro Version: %s
", allegro_id);
printf("ANY KEY DAMMIT!
");
system("pause");
allegro_exit();
return 0;
}
END_OF_MAIN() //this is used by the allegro lib
[/code]

Im getting :
[code]
`printf' undeclared (first use this function)
[/code]

the stdlib.h is in the includes folder.
Any ideas?

Comments

  • MT2002MT2002 Member Posts: 1,444

    printf is part if stdio.lib, so add one of the following at the top of your source file:
    [code]
    #include // C

    or:

    #include // C++
    [/code]
    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.mt2002.sitesled.com]Website[rightbr][/link][/size]
  • freelance starfreelance star Member Posts: 73
    : Hiya guys.. ive done some C and C++ in the (fairly distant) past,
    : and decided to have another go.
    : i got a Library called "Allegro" and installed it, and im using
    : Dev-C++
    :
    : Ok.. so program to test Allegro version, using the allegro library:
    :
    : [code]:
    : #include
    : #include
    :
    :
    : int main()
    : {
    : allegro_init();
    : printf("allegro Version: %s
    ", allegro_id);
    : printf("ANY KEY DAMMIT!
    ");
    : system("pause");
    : allegro_exit();
    : return 0;
    : }
    : END_OF_MAIN() //this is used by the allegro lib
    : [/code]:
    :
    : Im getting :
    : [code]:
    : `printf' undeclared (first use this function)
    : [/code]:
    :
    : the stdlib.h is in the includes folder.
    : Any ideas?
    :
    If it is C++, please use cout and cin.
    [B][link=http://expert.myitcareer.org/]Freelance Programmer[/link]|[link=http://myitcareer.org/]Interview Question And Answer[/link][/B]
  • JakykongJakykong Member Posts: 103
    : : Hiya guys.. ive done some C and C++ in the (fairly distant) past,
    : : and decided to have another go.
    : : i got a Library called "Allegro" and installed it, and im using
    : : Dev-C++
    : :
    : : Ok.. so program to test Allegro version, using the allegro library:
    : :
    : : [code]: :
    : : #include
    : : #include
    : :
    : :
    : : int main()
    : : {
    : : allegro_init();
    : : printf("allegro Version: %s
    ", allegro_id);
    : : printf("ANY KEY DAMMIT!
    ");
    : : system("pause");
    : : allegro_exit();
    : : return 0;
    : : }
    : : END_OF_MAIN() //this is used by the allegro lib
    : : [/code]: :
    : :
    : : Im getting :
    : : [code]: :
    : : `printf' undeclared (first use this function)
    : : [/code]: :
    : :
    : : the stdlib.h is in the includes folder.
    : : Any ideas?
    : :
    : If it is C++, please use cout and cin.
    : [B][link=http://expert.myitcareer.org/]Freelance
    : Programmer[/link]|[link=http://myitcareer.org/]Interview Question
    : And Answer[/link][/B]

    cout and cin may be great in some situations. But there are times...
    I find if i'm trying to do more complicated things than simple line formatting (say, drawing a table), printf() and family do the job without the hassle of coercing cout.

    Use what you know, or what you think will do the job best. There's a reason C++ has all of C as well.

    Sincerely,
    Jakykong (Jack Mudge)
    [email protected]
  • MT2002MT2002 Member Posts: 1,444

    : cout and cin may be great in some situations. But there are times...
    : I find if i'm trying to do more complicated things than simple line
    : formatting (say, drawing a table), printf() and family do the job
    : without the hassle of coercing cout.

    printf/scanf class of routines has some problems that could easily
    cause data curruption, ie, no type saftey. Something as simple as:
    [code]
    printf ("%s"); // prints either null or garbage
    scanf ("%s"); // access violation
    [/code]
    A mistake like these can very easily accure in modifying large programs.

    Also, they are not extensible like cout/cin. cout/cin can do everything
    printf/scanf can--even more.

    Granted, it is true that they are a little harder to use then printf/scanf,
    there are reasons why you [b]dont[/b] want to use C inside C++. The above
    demenstrates some examples of why.

    I personally recommend using cout/cin instead for C++. However, because
    the OP asked about printf(), I answered with it.

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.mt2002.sitesled.com]Website :: OS Development Series[rightbr][/link][/size]
Sign In or Register to comment.