My program is displaying.....actual hearts

This is a discussion on My program is displaying.....actual hearts within the C Programming forums, part of the General Programming Boards category; I'm writing a program which takes a surname, and assigns a phonetic code to the name(SOUNDEX encoding) Anyway, for certain ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    My program is displaying.....actual hearts

    I'm writing a program which takes a surname, and assigns a phonetic code to the name(SOUNDEX encoding)

    Anyway, for certain names, the program is displaying a little 'heart' character instead of a number. There is nothing in the program directly instructing it to display a 'heart' character.
    What normally causes this?

    I don't want to display the code as it is coursework and I don't want direct help with the code.

    Thanks

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Wiretron
    What normally causes this?
    Attempting to print the character representation of an integer value such as 3 rather than the intended '3'.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       int value = 3;
       printf("%%d: %d, %%c : %c\n", value, value);
       value = '3';
       printf("%%d: %d, %%c : %c\n", value, value);
       return 0;
    }
    
    /* my output
    %d: 3, %c : 
    %d: 51, %c : 3
    */
    Last edited by Dave_Sinkula; 11-08-2005 at 05:42 PM. Reason: Added code.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Make sure you are initializing the variable that is holding this "heart" to zero. Like if it was a C-style string, it would be initialized like this:
    Code:
    char var[256]={0};
    If it's not initialized to zero then it may have that junk in it.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You probably just have %c instead of %d (or %i, which is the same thing as %d).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Wierd problem
    By Olidivera in forum C++ Programming
    Replies: 17
    Last Post: 05-06-2005, 05:50 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Displaying pointer's actual values in inheritance
    By Poof in forum C++ Programming
    Replies: 14
    Last Post: 07-29-2004, 08:34 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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