473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Converting integers to strings

hi there,

I have been struggling for a while with a client/server program. I have to authenticate in order to log on correctly. I have managed to get most things sorted, asking for username ( which is an integer ) and also and customer ID (also an int), storing them into an array and then sending the data over to my server. However when if I printf the data the on the server the numbers do not match, and I do not know why ?

Somebody said that i needed to convert my integers into strings in my client program before sending them to the server....how on earth do i do this ? Do i need to do it ?

I have tried looking through google but have been unable to find anything on this subject, anyone got any ideas ?

Thanks for reading !
Mar 25 '07 #1
4 1536
Savage
1,764 Expert 1GB
hi there,

I have been struggling for a while with a client/server program. I have to authenticate in order to log on correctly. I have managed to get most things sorted, asking for username ( which is an integer ) and also and customer ID (also an int), storing them into an array and then sending the data over to my server. However when if I printf the data the on the server the numbers do not match, and I do not know why ?

Somebody said that i needed to convert my integers into strings in my client program before sending them to the server....how on earth do i do this ? Do i need to do it ?

I have tried looking through google but have been unable to find anything on this subject, anyone got any ideas ?

Thanks for reading !
Function itoa converts int to string.Function syntax is:

char *itoa(int value, char *string, int radix);

where:

value - integer to be converted

string - points to location where converted number and terminating \0 are stored

radix - specifes the base used in converting value.Base isnumber beetwen 2-36,inclusive
Mar 25 '07 #2
Ok but what happens when i type in a long integer can i put an array name where value should be ?

i.e

char *itoa(int customer id[], char *string, int radix);
Mar 25 '07 #3
Savage
1,764 Expert 1GB
Ok but what happens when i type in a long integer can i put an array name where value should be ?

i.e

char *itoa(int customer id[], char *string, int radix);
Yes,you can.Only posible problem is that you must use a loop.

Here's a small example:

Expand|Select|Wrap|Line Numbers
  1.     int main(void)
  2.     {
  3.         int number[5],i;
  4.         char *string[25];
  5.         clrscr();
  6.         for(i=0;i<5;i++) number[i]=0,*string[i]='\0';
  7.         for(i=0;i<5;i++) number[i]=1+i;
  8.         for(i=0;i<5;i++)
  9.         {
  10.             itoa(number[i], string[i], 10);
  11.             *string[i-1]='\0';
  12.             printf("integer = %d string = %s\n", number[i], string[i]);
  13.         }
  14.                 getch();
  15.         return 0;
}
Mar 25 '07 #4
horace1
1,510 Expert 1GB
is the representation of integers on the client and server machines the same? i.e. number of bytes used to store an int and if they are big endian or little endian. If not you will have to transalate between the representations.
If you have less than 256 user codes you could use an unsigned char (which is a byte sized integer) to store the value.
Mar 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Peter Warder | last post by:
I'm still struggling with these conversions! The wider code is working well but I can't get the compiler to accept my attempts at converting Integers (back) into Strings. What's the trick? ...
9
by: Hugo Amselschlag | last post by:
Hi there, I've implemented a local system hook to suppress certain windows beeing displayed by the axWebbrowser control. Now I need some more information before I can decide, whether to suppress...
11
by: TomServo | last post by:
I am writing code that needs to run on a variety of Unix systems. I am calling the statvfs and statfs system calls and I need to to convert some of the integers returned to character strings....
2
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The...
1
by: jimmypringles | last post by:
Anyone knows how how to add "number" strings without converting them to integers? I came up with this function but it didn't work perfectly. e.g. I added "1998" and "8991" and the result was...
3
by: Jeff | last post by:
....still new to vb.net 2005 I understand the concept of arrays, and have used them in other languages, but was hoping that someone could get me started with something. I have a fairly long...
21
by: py_genetic | last post by:
Hello, I'm importing large text files of data using csv. I would like to add some more auto sensing abilities. I'm considing sampling the data file and doing some fuzzy logic scoring on the...
2
by: HONOREDANCESTOR | last post by:
I've been converting a dotnet dll to a com object so that it can be called from vb6. If I want to pass a structure to a routine in the com object, like this: Call MyRoutine(byref MyStruct as...
6
by: andrews | last post by:
I try to add strings with fixed length who are representing integers So I have to put spaces (I guesse) before short strings(from short integers). F.e. 12345 1 567 5432 54328
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.