Advertising (This ad goes away for registered users. You can Login or Register)

[Tutorial] Introduction to programming using C

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
waratte
Posts: 1320
Joined: Wed Oct 20, 2010 12:03 am

Re: [Tutorial] Introduction to programming using C (I)

Post by waratte »

frank wrote:irfanhb7 i bet ur on windows and that the cmd prompt just blinks right
well u can use getch to have it stop till u press a key
but that has nothing to do with return, u still need return
Actually, you don't have to return anything if you specify your function as "void".
irfanhb7 wrote:Oh ! You posted a tutorial.
I have one question and pls don't get angry.
Can we use void main() instead of int main and getch() instead of return 0 ?
Answer to question 1: http://www.gidnetwork.com/b-66.html
Advertising
frank
Posts: 211
Joined: Wed Mar 23, 2011 5:15 am
Location: northwest usa
Contact:

Re: [Tutorial] Introduction to programming using C (I)

Post by frank »

i knew that waratte :]
just he needs it for int main
well actually the app will still work
but its a crime to not have return in int main
ill betcha m0skit0 can explain why
Advertising
Sig shrink!
PSP 2000 6.60 ME-1.8
G1 - Super D 1.11
Samsung Galaxy Tab 2 GT-P5113 - CyanogenMod 10
PC - Windows 7 - P4 3.20ghz HT - 3 gb 756 mb RAM - ATI Radeon x600
Cardboard box server - Ubuntu Server :D - AMD Athlon XP 3000+ - 512mb RAM
waratte
Posts: 1320
Joined: Wed Oct 20, 2010 12:03 am

Re: [Tutorial] Introduction to programming using C (I)

Post by waratte »

frank wrote:i knew that waratte :]
just he needs it for int main
well actually the app will still work
but its a crime to not have return in int main
ill betcha m0skit0 can explain why
Here's some more information on the subject:
http://users.aber.ac.uk/auj/voidmain.shtml
ASKidwai
Posts: 937
Joined: Mon Jan 10, 2011 7:42 am
Location: 'Ere and There
Contact:

Re: [Tutorial] Introduction to programming using C (I)

Post by ASKidwai »

Oh, OK.
Thanks for the clarification but this code works with GCC but won't work with CC. Here is the code

Code: Select all

//Slightly modded Hello World

#include <stdio.h>

int main()
{ 
	printf("I hate the ; at the end. \n Lua really did teach bad habits \n");
	return(0);
}
It makes an executable with GCC but CC shows this

Code: Select all

 cc goodbye -o bye
goodbye: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
goodbye:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here
goodbye: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here
goodbye:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
goodbye: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here
goodbye: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here
goodbye: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
goodbye:(.dtors+0x4): first defined here
collect2: ld returned 1 exit status
EDIT: Don't you have to put

Code: Select all

return 0;
in a parenthesis like this

Code: Select all

return(0);
?
Image
Image
Image
Image
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: [Tutorial] Introduction to programming using C (I)

Post by m0skit0 »

frank wrote:irfanhb7 i bet ur on windows and that the cmd prompt just blinks right
well u can use getch to have it stop till u press a key
but that has nothing to do with return, u still need return
You're right, but as stated on the OP, no discussion about Windows-related stuff, so please keep this clean.
ASKidwai wrote:Thanks for the clarification but this code works with GCC but won't work with CC.
Quite strange. Use gcc then.
ASKidwai wrote:EDIT: Don't you have to put

return 0;

in a parenthesis like this

return(0);
Nope, you don't have to. You can do it if you like it better, but it's not mandatory.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
ASKidwai
Posts: 937
Joined: Mon Jan 10, 2011 7:42 am
Location: 'Ere and There
Contact:

Re: [Tutorial] Introduction to programming using C (I)

Post by ASKidwai »

m0skit0 wrote: Quite strange. Use gcc then.
I do...
m0skit0 wrote:Nope, you don't have to. You can do it if you like it better, but it's not mandatory.
OK, then

BTW, isn't C a middle-level language?
Image
Image
Image
Image
irfanhb7
Posts: 466
Joined: Wed Jan 26, 2011 2:46 pm
Location: In your nightmares

Re: [Tutorial] Introduction to programming using C (I)

Post by irfanhb7 »

Going to double boot 7 and linux ,will it cause any problems?? because last time I double booted xp on 7 I had a lot of problems.
BTW which version of linux shall I buy ?
Languages I know : C , C++ & Java
Image
Boy : There is something wrong with my phone.
Girl : What ?
Boy: It don't have your Phone Number.
Image
ASKidwai
Posts: 937
Joined: Mon Jan 10, 2011 7:42 am
Location: 'Ere and There
Contact:

Re: [Tutorial] Introduction to programming using C (I)

Post by ASKidwai »

irfanhb7 wrote:Going to double boot 7 and linux ,will it cause any problems?? because last time I double booted xp on 7 I had a lot of problems.
BTW which version of linux shall I buy ?
Depends on how you install it. I used to quadriple between Ubuntu , Fedora, Kubuntu and Windows 7 without any problems.

Linux is free :D
Image
Image
Image
Image
irfanhb7
Posts: 466
Joined: Wed Jan 26, 2011 2:46 pm
Location: In your nightmares

Re: [Tutorial] Introduction to programming using C (I)

Post by irfanhb7 »

From where can I get it because no one in my area uses linux.
Languages I know : C , C++ & Java
Image
Boy : There is something wrong with my phone.
Girl : What ?
Boy: It don't have your Phone Number.
Image
ASKidwai
Posts: 937
Joined: Mon Jan 10, 2011 7:42 am
Location: 'Ere and There
Contact:

Re: [Tutorial] Introduction to programming using C (I)

Post by ASKidwai »

Image
Image
Image
Image
Locked

Return to “Programming and Security”