View Full Version : Problem In gcc
jo-jo
iam a newbie in c\c++ ( iam newbie in everthing if u think so :D)
and i tried to compile that program :-
#include<stdio>
main ()
{
printf("hi, iam here\n Iwill 'Learn' coding with C\n");
return0;
}
when i compiled it with
gcc -o pro1 pro1.c
it gave me tat error :-
pro1.c:1:16: stdio: No such file or directory
pro1.c: In function `main':
pro1.c:5: `return0' undeclared (first use in this function)
pro1.c:5: (Each undeclared identifier is reported only once
pro1.c:5: for each function it appears in.)
so?
:D
angoranimi
1. its stdio.h
2. its "return 0"
3. if you're returning 0, then "int main()" to specify return type of main().
jo-jo
thanx yya basha and sorry for annoying:D
^3aFrEt^
u can write
void main () instead of int main ()
when using the void u won`t need to return 0 at the end of the function
but i don`t know if this stabdard or not
the prof at the lect. she use to use int main and return 0
with the mo3eed it was always void
about the header.h
i think if u put .h u will get warning during the compilation - but it will go on - since they used to put the extention of the header file in old versions of compiler - wa Allahu a3lam -
:)
uniball
Originally posted by ^3aFrEt^
u can write
void main () instead of int main ()
when using the void u won`t need to return 0 at the end of the function
but i don`t know if this stabdard or not
the prof at the lect. she use to use int main and return 0
with the mo3eed it was always void
about the header.h
i think if u put .h u will get warning during the compilation - but it will go on - since they used to put the extention of the header file in old versions of compiler - wa Allahu a3lam -
:)
#include <stdio.h>
int main()
{
printf("Microcrap is crap!\n");
return 0;
}
3afreet, You are mixing C and C++
in C
it's stdio.h
in C++ it's iostream "not even stdio"
C --> #include <stdio.h>
C++ -->
#include <iostream>
int main()
{
using std::io;
cout << "Microcrap is crap!" << endl;
return 0;
}
^3aFrEt^
oppppss
ma3lesh el gahel amma yefty ba2a :)
but there is something stdiolib.h or sdio.h in c++ too
anyway i`m sorry again :)
MadFarmAnimalz
Originally posted by ^3aFrEt^
u can write
void main () instead of int main ()
when using the void u won`t need to return 0 at the end of the function
but i don`t know if this stabdard or not
the prof at the lect. she use to use int main and return 0
with the mo3eed it was always void
about the header.h
i think if u put .h u will get warning during the compilation - but it will go on - since they used to put the extention of the header file in old versions of compiler - wa Allahu a3lam -
:)
you don't want to specify a void return type for main; nasty windows development habit.
Some of us console freaks actually *do* check return values for executed programs.
sattia
an errorlevel or a return value is a way executables use to report their status to the calling program when they exit. A calling program is either shell, or another program; php interpreter,perl ...etc.
a return value of 0 is used to indicate success
any other value is used to indicate failure.
In C; if a function does not have an explicitly specified return value; it is assumed to be of type int. So both of main() and int main() are equal from C point of view. BTW gcc raises several warnings (with -Wall option):
    - if u use main() and u do not return a value -> warning: control reaches end of non-void function
    - if u use main() and u return a value -> warning: return type defaults to `int'
    - if u use int main() and u return a value -> doesnt return any warnings
Some programs use error levels to indicate several situations. But this is a program dependent.
alaa
the C++ ANSI/ISO standard states that main has to return an int.
so void main() is not valid C++.
if you want to use standard C library calls then include the headers this way
#include <cstdio>
the math header would be <cmath>, the time header would be <ctime> etc.
this is very important since the <c*> headers inform the compiler that these files include C not C++ code.
in general it is not recommended that you use C IO functions in your C++ code, it'll even perform better than C since printf is an interpreter that the format of the print out at run time, while the iostream objects does most binding at compile time. (but I have to admit that the iostream objects are quite large).
make sure you learn C++ from a modern book, there has been some changes in the language 8 yars ago but compilers and book writers have been slow on catching up.
cheers,
Alaa
vBulletin v3.0.1, Copyright ©2000-2004, Jelsoft Enterprises Ltd.