473,666 Members | 2,565 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 1065
Sunil <sr*******@gmai l.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!abcdef gh", 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 "interestin g" relationship between the input and the
output?

--
Ben.
Jun 27 '08 #2
In article <81************ *************** *******@q24g200 0prf.googlegrou ps.com>,
Sunil <sr*******@gmai l.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*******@gmai l.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!abcdef gh";
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.l earn.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...@gmai l.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!abcdef gh", 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 "interestin g" 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************ *************** *******@r9g2000 prd.googlegroup s.com>,
sunny <sr*******@gmai l.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
1602
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 have also to decide on the approach for doing this. The Destination Format needs to be configurable so that the source XML that I have can be converted to the desired destination format looking at the schema stored in some configuration file. I need...
7
5206
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 identical data layout. I have used this idea with no problem, but it necessitates making changes very carefully to the Fortran module and the C++ structure to keep them "in sync". I am looking for a program which translates source files between...
6
4829
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 W3C note: http://www.w3.org/TR/NOTE-datetime For my requirements the code would be need to be open sourceable under the BSD license.
8
7852
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 yet to code from scratch. I could learn quickly from an example that reads,formats then outputs. If anyone has an example code I would like to see it. Thanks, Spacepie
1
1545
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 have also to decide on the approach for doing this. The Destination Format needs to be configurable so that the source XML that I have can be converted to the desired destination format looking at the schema stored in some configuration file. I need...
4
3325
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 the mysql database. I believe the field in mysql is wanting UTC and shows numbers when looked at from the sql command line (i.e. March 13, 2006, 5:31 pm is shown as 1142289086). How do I get the access data into that format so it will import...
1
3739
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
1737
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 entries preferably to Date but in formats above? i tried to do: "update table_name set column_name = to_date('2008', 'YYYY') where c_id = 12"
5
17014
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 4 bytes ) we defined #ifdef WIN32 #define t_wchar_t wchar_t #else // LINUX #define t_wchar_t short
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4192
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.