473,507 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: converting int values to other formats

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 #
Jun 27 '08 #1
5 1056
Sunil <sr*******@gmail.comwrites:
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.
Jun 27 '08 #2
In article <81**********************************@q24g2000prf. googlegroups.com>,
Sunil <sr*******@gmail.comwrote:
>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
Jun 27 '08 #3
On Sat, 26 Apr 2008 20:14:37 -0700 (PDT), Sunil <sr*******@gmail.com>
wrote in comp.lang.c:
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 #
Your question does not make it very clear what it is that you are
trying to do.

One easy way to have an arbitrary one-to-one map of one set of
characters to another is to have an array of structures like this:

struct char_map { int in, int out };

struct char_map table [] =
{
{ '7', '"' },
{ '8', 'v' },
/* and so on, for however many you need */
};

Then when you receive an input character, you search the first member
of every structure in the array to see if there is a match. If there
is, you output the second member of the structure.

Another possibility is to use a pair of strings:

const char inputs [] = "789!abcdefgh";
const char output [] = "\"v$@#@E@%#G#";

You can search the input string for the input character with strchr(),
and use its distance from the start of the string (if it is found) to
compute the index into the replacement string.

In either approach, you have to decide what to do if the input does
not match one of your defines substitution patterns.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jun 27 '08 #4
On Apr 26, 8:54 pm, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Sunil <sravip...@gmail.comwrites:
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
Jun 27 '08 #5
In article <fb**********************************@r9g2000prd.g ooglegroups.com>,
sunny <sr*******@gmail.comwrote:
>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
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1596
by: Rishit | last post by:
Hello All, I have to convert XML data (that may be received through a dataset) to other formats such as CSV, Excel etc. Are there any libraries or sample code that would help me do this task. I...
7
5195
by: Anonymous | last post by:
I have a mixed-language pgm (Fortran and C++) which needs to pass a few hundred values from C++ to Fortran. One way to do this is to have a Fortran module and a C++ structure (or class) with an...
6
4824
by: Jim Davis | last post by:
Before I reinvent the wheel I thought I'd ask: anybody got a code snippet that will convert the common ISO8601 date formats to a JS date? By "common" I mean at the least ones described in this...
8
7840
by: spacepie | last post by:
Does anyone have sample coding to do this. I have a legacy app which generates great data but it's in PRN format. I need to convert this to CSV format for importing. I don't know C++ well enouch...
1
1537
by: Rishit | last post by:
Hello All, I have to convert XML data (that may be received through a dataset) to other formats such as CSV, Excel etc. Are there any libraries or sample code that would help me do this task. I...
4
3309
by: Dan Lewis | last post by:
I've imported a ms access database into a table in a mysql database. The access database contains a field that holds date/time values in 'general date' format. These all show up at 01/01/1970 in...
1
3718
by: Johanna Pfalz | last post by:
Is there a module/method in python to convert a file from .DBF format to ..CSV format? Johanna Pfalz
4
1724
by: nikos | last post by:
Hi, I have a table with one of the columns configured to record dates as ('#', 'MM/DD/YYYY'). However, two entries in that column are of format YYYY and MM/YYYY. How can I change only those two...
5
16947
by: yakir22 | last post by:
Hello experts, I am dealing now in porting our server from windows to linux. our client is running only on windows machine. to avoid the wchar_t size problem ( in windows its 2 bytes and linux is...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.