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

Black Friday Sale: Playstation Plus 1 Year subscription is $39.99 (33% off) on Amazon and other retailers, while supplies last.

[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 » Sun May 15, 2011 10:54 pm

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 » Sun May 15, 2011 11:02 pm

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 » Sun May 15, 2011 11:07 pm

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 » Mon May 16, 2011 3:35 am

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

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

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

Post by m0skit0 » Mon May 16, 2011 6:53 am

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 » Mon May 16, 2011 6:56 am

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 » Mon May 16, 2011 6:58 am

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 » Mon May 16, 2011 7:08 am

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 » Mon May 16, 2011 7:12 am

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 » Mon May 16, 2011 7:16 am

Image
Image
Image
Image

Post Reply

Return to “Programming and Security”