Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


I made a simple C application

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Wed Jan 09, 2008 2:19 pm    Post subject: I made a simple C application Reply with quote

not long ago, i started learning C (i have a book)

here's my fifth (i think) application, don't laugh Embarassed

Code:
#include <stdio.h>

void main(void)
{
   int a,b,c;

   printf("Insert first number: \n");
   scanf("%d",&a);
   printf("Insert second number: \n");
   scanf("%d",&b);
   printf("Insert third number: \n");
   scanf("%d",&c);

   if ((a>b) & (a>c))
      printf("First number is bigger");
   else
      if ((b>a) & (b>c))
         printf("Second number is bigger");
      else
         if ((c>b) & (c>a))
            printf("Third number is bigger");
         else
            if ((a=b) || (a=c) || (b=a) || (b=c) || (c=a) || (c=b))
               printf("All numbers are equal");
}
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Wed Jan 09, 2008 3:01 pm    Post subject: Reply with quote

Very nice.
But the last if could be better:
Code:
if ((a==b) && (b==c))
               printf("All numbers are equal");


Edit: * fixed syntax.


Last edited by HolyBlah on Thu Jan 10, 2008 2:47 am; edited 1 time in total
Back to top
View user's profile Send private message
Aikos
Cheater
Reputation: 0

Joined: 26 Nov 2007
Posts: 47

PostPosted: Thu Jan 10, 2008 2:40 am    Post subject: Reply with quote

Dont you use == instead of = when you are checking for equality?
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Jan 10, 2008 2:42 am    Post subject: Reply with quote

Aikos wrote:
Dont you use == instead of = when you are checking for equality?


Lol, yes
Back to top
View user's profile Send private message MSN Messenger
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Thu Jan 10, 2008 2:46 am    Post subject: Reply with quote

Aikos wrote:
Dont you use == instead of = when you are checking for equality?
wops, my bad. Embarassed
Didn't touch C for like a 64 month.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Thu Jan 10, 2008 2:52 am    Post subject: Reply with quote

Aikos wrote:
Dont you use == instead of = when you are checking for equality?


That use of = is not always incorrect, he could have been setting some variables and then testing them, for example:

Code:

FILE *fp;
if ((fp = fopen("a.txt", "r")) != NULL)
{
     //fp is valid, we can use it
     fclose(fp);
}

_________________
Back to top
View user's profile Send private message
benlue
Moderator
Reputation: 0

Joined: 09 Oct 2006
Posts: 2142

PostPosted: Thu Jan 10, 2008 2:59 am    Post subject: Reply with quote

That's true appalsap but i doubt he is actually testing them.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Thu Jan 10, 2008 5:44 am    Post subject: Reply with quote

i checked wikipedia for C operators, and it said that:

|| Logical OR

& AND

etc..

what's the diff between, & and && ? or = and == ?

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B

btw, when you add a library (.h, header) file, what's the diffrent between:

<windows.h> and "windows.h" ?

@ HolyBlah:

yeah, i was thinking there would be a way to optimise that block, thanks
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Thu Jan 10, 2008 6:31 am    Post subject: Reply with quote

'=': Assigning operator:
Code:
Int=8+5;

'&', '|', '^': Binary commands:
Code:
Int:8 & 9
mean:
Code:

&:
8 =   1000
9 =   1001
17 = 10001

|:
9  = 1001
10 = 1010
11 = 1011

^(Xor):
9  = 1001
10 = 1010
3  = 0011


'&&', '||':Compare operator:
Code:
command = ((5+3==9)||(3+1==4)).
(5+3=9) = False.
(3+1=4) = True.
((5+3==9)||(3+1==4)) = True.


command = ((5+3==9)&&(3+1==4)).
(5+3=9) = False.
(3+1=4) = True.
((5+3==9)&&(3+1==4)) = False.
Back to top
View user's profile Send private message
nox
Expert Cheater
Reputation: 0

Joined: 09 Apr 2007
Posts: 227
Location: brooklyn

PostPosted: Thu Jan 10, 2008 7:09 am    Post subject: Reply with quote

you could have reduced the amount of code in the last line by using previous indication but good work either way Razz
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Fri Jan 11, 2008 5:16 am    Post subject: Reply with quote

Kaspersky wrote:
btw, when you add a library (.h, header) file, what's the diffrent between:

<windows.h> and "windows.h" ?
The path where does the compiler look for the file.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Jan 11, 2008 7:54 am    Post subject: Reply with quote

Jani wrote:
Kaspersky wrote:
btw, when you add a library (.h, header) file, what's the diffrent between:

<windows.h> and "windows.h" ?
The path where does the compiler look for the file.


can you give me an example ?

like <windows.h> or "X:\windows.h" ?
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Jan 11, 2008 4:57 pm    Post subject: Reply with quote

Kaspersky wrote:
like <windows.h> or "X:\windows.h" ?


" " : Look in the projects folder. Then if not found look in the includes.
< > : Skip the project folder and just look in the includes.

Also, your lack of {}s is annoying. A lot of people try and shorten up their code by not using them, but generally it is more readable to leave them in. There are a few situations however where you would be better off without them.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Sat Jan 12, 2008 3:57 am    Post subject: Reply with quote

Flyte wrote:
Kaspersky wrote:
like <windows.h> or "X:\windows.h" ?


" " : Look in the projects folder. Then if not found look in the includes.
< > : Skip the project folder and just look in the includes.

Also, your lack of {}s is annoying. A lot of people try and shorten up their code by not using them, but generally it is more readable to leave them in. There are a few situations however where you would be better off without them.


very nice explained, thanks

and yeah, about the {} the book didn't toled me (yet) to use {} in this assignment
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites