Re: converting int values to other formats

Discussion in 'C Programming' started by Sunil, Apr 27, 2008.

  1. Sunil

    Sunil Guest

    I am trying to see as to what kind of input such as below can produce
    a output. If you see for input 7, the output is " and for 8 is v. I am
    trying to determine what can generate an output in this format using C

    Thanks

    Please enter a key to continue : 7
    Input 7 Output "
    Please enter a key to continue : 8
    Input 8 Output v
    Please enter a key to continue : 9
    Input 9 Output $
    Please enter a key to continue : !
    Input ! Output @
    Please enter a key to continue : a
    Input a Output #
    Please enter a key to continue : b
    Input b Output @
    Please enter a key to continue : c
    Input c Output E
    Please enter a key to continue : d
    Input d Output @
    Please enter a key to continue : e
    Input e Output %
    Please enter a key to continue : f
    Input f Output #
    Please enter a key to continue : g
    Input g Output G
    Please enter a key to continue : h
    Input h Output #
     
    Sunil, Apr 27, 2008
    #1
    1. Advertising

  2. Sunil <> writes:

    > I am trying to see as to what kind of input such as below can produce
    > a output. If you see for input 7, the output is " and for 8 is v. I am
    > trying to determine what can generate an output in this format using C
    >
    > Please enter a key to continue : 7
    > Input 7 Output "
    > Please enter a key to continue : 8
    > Input 8 Output v
    > Please enter a key to continue : 9
    > Input 9 Output $
    > Please enter a key to continue : !
    > Input ! Output @
    > Please enter a key to continue : a
    > Input a Output #
    > Please enter a key to continue : b
    > Input b Output @
    > Please enter a key to continue : c
    > Input c Output E
    > Please enter a key to continue : d
    > Input d Output @
    > Please enter a key to continue : e
    > Input e Output %
    > Please enter a key to continue : f
    > Input f Output #
    > Please enter a key to continue : g
    > Input g Output G
    > Please enter a key to continue : h
    > Input h Output #


    That is a little under-specified. One possible answer is:

    #include <stdio.h>
    #include <string.h>

    int main(void)
    {
    char c, *r, src[] = "789!abcdefgh", dst[] = "\"v$@#@E@%#G#";
    while (printf("Please enter a key to continue : ") > 0 &&
    fflush(stdout) == 0 &&
    scanf(" %c", &c) == 1)
    if (r = strchr(src, c))
    printf("Input %c Output %c\n", c, dst[r - src]);
    return 0;
    }

    but you almost certainly don't mean that. Are you asking if anyone
    can spot an "interesting" relationship between the input and the
    output?

    --
    Ben.
     
    Ben Bacarisse, Apr 27, 2008
    #2
    1. Advertising

  3. In article <>,
    Sunil <> wrote:
    >I am trying to see as to what kind of input such as below can produce
    >a output. If you see for input 7, the output is " and for 8 is v. I am
    >trying to determine what can generate an output in this format using C


    Possibly:

    malloc() space to hold the character and then print the -pointer-
    using a %c format.

    If so, then entering the same character twice would not necessarily
    have the same result each time.


    Or, just index by the input character into an uninitialized
    offset in memory. Could be nearly anything there. Might happen
    to hit machine instructions, for example.


    Other than that, I don't see any particular pattern. I was thinking
    perhaps some nands and xors, but if it is that, it would have to be
    a number of them, not something simple.
    --
    "If there were no falsehood in the world, there would be no
    doubt; if there were no doubt, there would be no inquiry; if no
    inquiry, no wisdom, no knowledge, no genius."
    -- Walter Savage Landor
     
    Walter Roberson, Apr 27, 2008
    #3
  4. Sunil

    sunny Guest

    On Apr 26, 8:54 pm, Ben Bacarisse <> wrote:
    > Sunil <> writes:
    > > I am trying to see as to what kind of input such as below can produce
    > > a output. If you see for input 7, the output is " and for 8 is v. I am
    > > trying to determine what can generate an output in this format using C

    >
    > > Please enter a key to continue : 7
    > > Input 7 Output "
    > > Please enter a key to continue : 8
    > > Input 8 Output v
    > > Please enter a key to continue : 9
    > > Input 9 Output $
    > > Please enter a key to continue : !
    > > Input ! Output @
    > > Please enter a key to continue : a
    > > Input a Output #
    > > Please enter a key to continue : b
    > > Input b Output @
    > > Please enter a key to continue : c
    > > Input c Output E
    > > Please enter a key to continue : d
    > > Input d Output @
    > > Please enter a key to continue : e
    > > Input e Output %
    > > Please enter a key to continue : f
    > > Input f Output #
    > > Please enter a key to continue : g
    > > Input g Output G
    > > Please enter a key to continue : h
    > > Input h Output #

    >
    > That is a little under-specified. One possible answer is:
    >
    > #include <stdio.h>
    > #include <string.h>
    >
    > int main(void)
    > {
    > char c, *r, src[] = "789!abcdefgh", dst[] = "\"v$@#@E@%#G#";
    > while (printf("Please enter a key to continue : ") > 0 &&
    > fflush(stdout) == 0 &&
    > scanf(" %c", &c) == 1)
    > if (r = strchr(src, c))
    > printf("Input %c Output %c\n", c, dst[r - src]);
    > return 0;
    >
    > }
    >
    > but you almost certainly don't mean that. Are you asking if anyone
    > can spot an "interesting" relationship between the input and the
    > output?
    >
    > --
    > Ben.



    Thanks, yes. I am trying to get any correlation. If you repeat the
    input then the output is not the same either. I took a rand() number,
    cast it to a char and saw the output. In this particular case, the
    output seem to be within the [0 -9] and [a-z A-Z]
    Appreciate all your replies.

    Sunny
     
    sunny, Apr 27, 2008
    #4
  5. In article <>,
    sunny <> wrote:

    >Thanks, yes. I am trying to get any correlation. If you repeat the
    >input then the output is not the same either. I took a rand() number,
    >cast it to a char and saw the output. In this particular case, the
    >output seem to be within the [0 -9] and [a-z A-Z]


    "the output" is a bit ambiguous; it isn't clear if you are talking
    about the original output you showed us, or the output of the
    program that used rand(). If you are talking about the original
    output, then may you have not noticed the fact that the most common
    output was # and that " $ @ % occured as well.

    If you repeat the input and the output is different, there isn't
    necessarily any logic to the outputs. Try repeating the same
    input over and over and seeing if a pattern develops or if
    characters outside of the printable ASCII range show up.
    --
    "Walter exemplified class." -- Paul Tagliabue
     
    Walter Roberson, Apr 28, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,236
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,680
    Old Wolf
    Jan 20, 2004
  3. arun
    Replies:
    8
    Views:
    465
    Dave Thompson
    Jul 31, 2006
  4. Replies:
    6
    Views:
    1,562
    Richard Tobin
    Mar 19, 2009
  5. jdm
    Replies:
    1
    Views:
    671
    Victor Bazarov
    May 18, 2010
Loading...

Share This Page