LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error :In function 'main': (https://www.linuxquestions.org/questions/programming-9/error-in-function-main-499405/)

studentlb 11-07-2006 08:42 AM

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

bernied 11-07-2006 08:52 AM

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:')?

demon_vox 11-07-2006 08:53 AM

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!

studentlb 11-07-2006 09:01 AM

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???

bernied 11-07-2006 09:41 AM

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.

soggycornflake 11-07-2006 10:40 AM

You should never use gets, as is explicitly stated in the man page. It is broken. Use fgets instead.

demon_vox 11-07-2006 11:41 AM

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 :D ) 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!

studentlb 11-07-2006 12:54 PM

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 ??

soggycornflake 11-07-2006 12:57 PM

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);


studentlb 11-07-2006 01:07 PM

Thank you i ll try it :)

studentlb 11-08-2006 10:54 AM

Thanks :) i solved it :)

bernied 11-08-2006 04:27 PM

I'm also learning C. This seems a good tutorial:
http://www.crasseux.com/books/ctutorial/

studentlb 11-08-2006 04:57 PM

Thanks a lot :)


All times are GMT -5. The time now is 05:25 PM.