LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-07-2006, 08:42 AM   #1
studentlb
Member
 
Registered: Oct 2006
Posts: 53

Rep: Reputation: 15
error :In function 'main':


Hi All,

Please i need ur help
i compiled 2 examples and it s giving me the following error:
In function 'main':
pls how can it b solved??
Thanks
 
Old 11-07-2006, 08:52 AM   #2
bernied
Member
 
Registered: Mar 2006
Location: Edinburgh, UK
Distribution: debian
Posts: 304

Rep: Reputation: 30
This is not really enough information for anyone to help you. The actual error(s) will be on the line(s) displayed below 'In function main:'. All we can say from this is that you tried to compile something, which has a function called main, and there was an error in compiling that part of the code.

So
- 2 examples of what?
- what is the code you were trying to compile (you can post it here)?
- what is the actual error (displayed below 'In function main:')?
 
Old 11-07-2006, 08:53 AM   #3
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Hi,
"in function 'main':" is not an error, so there is nothing to be solved
If you want to get a solution, please post the error!

Cheers!
 
Old 11-07-2006, 09:01 AM   #4
studentlb
Member
 
Registered: Oct 2006
Posts: 53

Original Poster
Rep: Reputation: 15
actually, this is the error i m getting:

/tmp/ccydIKZQ.o: In function `main':
csc1.c.text+0x288): warning: the `gets' function is dangerous and should not be used


i ll supply u with the code when i go home

does this kind of error make sense to u, did i get this error cz of the gets???

Last edited by studentlb; 11-07-2006 at 09:14 AM.
 
Old 11-07-2006, 09:41 AM   #5
bernied
Member
 
Registered: Mar 2006
Location: Edinburgh, UK
Distribution: debian
Posts: 304

Rep: Reputation: 30
While not familiar with the function gets, that message is not an error as such, but a warning. Are you sure that the compile did not work? Look for a binary file nearby that wasn't there before.

If you have access to linuxquestions you have access to google. Googling 'gets function C' gave me this page as first choice:
http://www.crasseux.com/books/ctutorial/gets.html
Seems very clear to me.
 
Old 11-07-2006, 10:40 AM   #6
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
You should never use gets, as is explicitly stated in the man page. It is broken. Use fgets instead.
 
Old 11-07-2006, 11:41 AM   #7
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Thats not an error, thats a warning. Which means that you did get a succesful compilation. You'd probably missed the a.out binary which must be there.
Either way, soggycornflake is right. gets is a dangerous function (as the compiler said also ) because it doesnot check for a buffer overflow. So read the man for that function and search for an alternative (like fgets as, once again, soggycornflake stated before)

Cheers!
 
Old 11-07-2006, 12:54 PM   #8
studentlb
Member
 
Registered: Oct 2006
Posts: 53

Original Poster
Rep: Reputation: 15
i run the program, as it seems it is executing correclty but i m afraid of these errors and i want to compile without getting any error or warning. I will change the gets to fgets and recompile it
Thanks !
p.s: can i just insert fgets instead of gets or i have to change it all ??
 
Old 11-07-2006, 12:57 PM   #9
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
fgets requires the buffer size and a file stream, in addition to the buffer. RTFM!

Code:
char buffer[80];
gets(buffer);
becomes

Code:
char buffer[80];
fgets(buffer, sizeof(buffer), stdin);
 
Old 11-07-2006, 01:07 PM   #10
studentlb
Member
 
Registered: Oct 2006
Posts: 53

Original Poster
Rep: Reputation: 15
Thank you i ll try it
 
Old 11-08-2006, 10:54 AM   #11
studentlb
Member
 
Registered: Oct 2006
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks i solved it
 
Old 11-08-2006, 04:27 PM   #12
bernied
Member
 
Registered: Mar 2006
Location: Edinburgh, UK
Distribution: debian
Posts: 304

Rep: Reputation: 30
I'm also learning C. This seems a good tutorial:
http://www.crasseux.com/books/ctutorial/
 
Old 11-08-2006, 04:57 PM   #13
studentlb
Member
 
Registered: Oct 2006
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks a lot
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Override main function in C joeyBig Programming 8 03-19-2018 06:37 AM
How many prototype of function main in c? ypzhuang Programming 9 12-13-2008 07:53 AM
Can i call yyparse from a function other than main? pragnya Programming 2 06-30-2006 03:29 AM
what's the kernel's main() function? LordOfer Linux - General 1 04-06-2005 03:02 PM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration