Smiley Faces?

This is a discussion on Smiley Faces? within the C Programming forums, part of the General Programming Boards category; Ok, in my vain attempt to learn up on strings before my exams I made this program to better understand ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    173

    Smiley Faces?

    Ok, in my vain attempt to learn up on strings before my exams I made this program to better understand getchar().

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
      int c;
      int i = 0;
      int d;
    
      char storage[100];
      printf("Input a phrase: ");
      
      while(c = getchar() != '\n'){
      storage[i++] = c;
      }
    
      printf("\n\nEchoing: \n");
      for(d = 0; d < i; d++)
    	  printf("%c ",storage[d]);
    
      return 0;
    }
    The problem is the outputs are always smiley faces?? What's going on?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You've missed some brackets, you need this:
    while ((c = getchar()) != '\n')
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could also try...

    if( c != && c != and c != ) printf("%c", c );




    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    syntax error quzah
    if( c != && c != and c != ) printf("%c", c );

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Nah, I just forgot to include my define with that code snippet:
    Code:
    #define and &&
    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Sure you did

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Quote Originally Posted by quzah
    Nah, I just forgot to include my define with that code snippet:
    Code:
     #define and &&
    Quzah.
    Na, you were just using C99, and forgot to show the includes:
    Code:
     7.9 Alternative spellings <iso646.h>
     1 The header <iso646.h> defines the following eleven macros (on the left) that expand
     to the corresponding tokens (on the right):
     and &&
     and_eq &=
     bitand &
     bitor |
     compl ~
     not !
     not_eq !=
     or ||
     or_eq |=
     xor ^
     xor_eq ^=
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Na, you were just using C99
    ios646.h was a new header in Normative Addendum 1, an addition registered with ISO in 1994. So it's been around for a while and should be available in compilers that support C95 (which should be most modern compilers).
    My best code is written with the delete key.

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    what's better? does it even matter?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >what's better? does it even matter?
    Huh?
    My best code is written with the delete key.

  11. #11
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    the C95 and C99
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Define better.

  13. #13
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >the C95 and C99
    Oh. Well, C99 is clearly better (according to ISO), but it isn't well implemented yet, so we can't really use it with confidence. C95 is an amendment to C89/90 and everyone just refers to C95 as C89/90 or just C89 or just C90. You're probably using a C95 compiler but not a C99 compiler, so it matters quite a bit.
    My best code is written with the delete key.

  14. #14
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    do you know if borland 5.5 supports C99?

    and what makes it so good, according to ISO?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >do you know if borland 5.5 supports C99?
    Yes, I do and no, it doesn't.

    >and what makes it so good, according to ISO?
    Well, every new feature. The committee has been pushing for a pointer aliasing restriction for almost 20 years now, so they're probably thrilled about restrict. C now supports variable length arrays, albeit with funky syntax snags that I'm not fond of. We can (finally!) use compound literals and named initializers. Pretty much anything new was seen as an improvement even though some people wouldn't agree with that assessment.
    My best code is written with the delete key.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D rendering of only visible faces
    By Zeeshan in forum Game Programming
    Replies: 5
    Last Post: 02-23-2009, 06:52 PM
  2. smiley faces ????
    By goran00 in forum C Programming
    Replies: 7
    Last Post: 04-17-2008, 11:58 AM
  3. OpenGL cube's faces mess up
    By ay_okay in forum Game Programming
    Replies: 5
    Last Post: 06-08-2005, 08:05 PM
  4. Sending problem, or 1 = smiley face
    By Asmodeus in forum Tech Board
    Replies: 1
    Last Post: 04-25-2005, 12:01 PM
  5. Your Favorite Smiley...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-22-2001, 11:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21