Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 14:45

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: C help.
PostPosted: 25 Feb 2008 19:32 

Joined: 24 Sep 2007 02:12
Posts: 1114
Location: http://sethioz.co.uk
ok i am trying to do some simple thing, but it doesnt work.
what i wanna make is just simple program that prints the specified thing.
problem is that it does not print what i choose...it prints out everything when i use the ''if'' command.
ill give an example:

Code:
  printf( "\nEnter letter from name ''Sethioz'' to be shown below: \n" );
 
  char S, e, t, h, i, o, z; 
  scanf( "%s", &S, e, t, h, i, o, z );
 
  if ( S == S, e, t, h, i, o, z )
    printf( "S test" );
   
  if ( e == S, e, t, h, i, o, z )
    printf( "e test" );

  printf( "\nentered %s" );
  getchar();


i know that its wrong, but how can i make it print only ONE of them ? right now it prints both. Its just a part of it ... ill add ''else'' if you enter something else than those letters...etc. I know im missing something easy .. but what ? worked fine with numbers and when i used ==, !=, < or >.


Top
 Profile  
 
 
 Post subject:
PostPosted: 25 Feb 2008 23:17 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
wow there are so much bugs in that code that I don't know where starting 8-)

scanf( "%s", &S, e, t, h, i, o, z );
first error: S is one byte while %s is for strings and then you have specified also all the other variables which are not used (one format argument, not seven)

then if ( S == S, e, t, h, i, o, z ) wrong again for the same reason of before (S == S is ever true and e, t, h, i, o, z are not needed)

printf( "\nentered %s" );
here is missed the argument


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2008 16:46 

Joined: 24 Sep 2007 02:12
Posts: 1114
Location: http://sethioz.co.uk
well its just quick example i put togheter.
( S == S, e, t, h, i, o, z ) - i tried S == S, e == e....it still printed out everything. (maybe cuz of the scanf error)

uhm ..what i do about %s ? well string cant be one letter ? what do i use then ? %n is for numbers right ?


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2008 17:29 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
printf( "\nentered %s", "hello" );


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2008 21:47 

Joined: 05 Oct 2007 01:20
Posts: 402
Location: Florida
i thought %d was numbers


Top
 Profile  
 
 Post subject:
PostPosted: 27 Feb 2008 22:47 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
yes, %d and %i are for integers and %u for unsigned.
The printf formatters are a lot.


Top
 Profile  
 
 Post subject:
PostPosted: 28 Feb 2008 13:52 

Joined: 24 Sep 2007 02:12
Posts: 1114
Location: http://sethioz.co.uk
oops...my bad.
havent tried it yet with modifications ... but ill try soon and see what happens.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC [ DST ]


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 post attachments in this forum

Search for: