473,396 Members | 1,998 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,396 software developers and data experts.

sprintf and C#

hey i wrote a progam a wihle back in c++ and i used the sprintf function as follows:

OVERLAPPED osWait = {0};
DWORD dwWritten;

char B[20];

sprintf (B, "\x02" "CB 0 1" "\x0D\x0A\x03");
WriteFile (m_hPort, B, strlen(B), &dwWritten, &osWait);

how do i change this to c#.. just the sprintf part.

From http://www.developmentnow.com/g/36_0...ges-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 17 '05 #1
2 9772
steve wrote:
hey i wrote a progam a wihle back in c++ and i used the sprintf
function as follows:

OVERLAPPED osWait = {0};
DWORD dwWritten;

char B[20];

sprintf (B, "\x02" "CB 0 1" "\x0D\x0A\x03");
WriteFile (m_hPort, B, strlen(B), &dwWritten, &osWait);

how do i change this to c#.. just the sprintf part.

From
http://www.developmentnow.com/g/36_0...ges-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com


With String.Format you can do similar things. The syntax in entirely different though.

Hans Kesting
Nov 17 '05 #2

"steve" <st********@hotmail.com> wrote in message
news:90**********************************@msnews.m icrosoft.com...
hey i wrote a progam a wihle back in c++ and i used the sprintf function
as follows:

OVERLAPPED osWait = {0};
DWORD dwWritten;

char B[20];

sprintf (B, "\x02" "CB 0 1" "\x0D\x0A\x03");
WriteFile (m_hPort, B, strlen(B), &dwWritten, &osWait);

how do i change this to c#.. just the sprintf part.

From
http://www.developmentnow.com/g/36_0...ges-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com


string s = '\x02' + "CB 0 1\r\n" + '\x03'
or
s = '\x02' + "CB 0 1" + '\x0d' + '\x0a' + '\x03'
or
const char stx = '\x02';
const char etx = '\x03';
s = stx + "CB 0 1\r\n" + etx;
....

Willy.
Nov 17 '05 #3

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

Similar topics

13
by: Yodai | last post by:
Hi all.... I have a little problem that's driving me nuts. I can't seem to make any sense of it. I have this small webserver that substitutes some data from a page when finds a substitution...
3
by: huey_jiang | last post by:
Hi All, I am trying to figure out a right syntax to convert an integer array into hex array. sprintf worked for me on doing single integer: int i, Iarray, n=15; char buf; sprintf(buf,...
6
by: jt | last post by:
I need to produce 1 character array from 3 others. I tried sprintf and it terminates on the first 0, null, 0x00 it sees in tmp data. All 3 args print out nice by themselves. By trying to make...
1
by: jimjim | last post by:
Hello, I was wondering about the implications of giving as an argument to sprintf a different data type from the one specified in the format argument. This type of question along with some...
2
by: aap | last post by:
I have the following code #define MAX 32 struct A { char carr; int iarr; int i; }; void main() {
9
by: Neal Barney | last post by:
I have a C program which runs on a device using a Zilog Z180 microprocessor. While it can address 1MB of RAM, it can only address 64KB at any given time. And of that only 16KB can be used for...
12
by: Henryk | last post by:
Hey there, I have some problems with the following code snippet on a Virtex-4 PowerPC with a GCC based compiler char chData; sprintf(&chData, "%+05.0f", -0.038f); --I get "-000" ???...
15
by: krister | last post by:
Hello, I'm working in a quite large system that has some limitations. One of those is that I can't use printf() to get an output on a screen. I'm forced to use a special function, let's call it...
5
by: Dave | last post by:
Hi, In awk I can do this: var1="x"; temp = sprintf("Variable 1: %s Variable 2: %%s", var1); # now the value of temp is "Variable 1: x Variable 2: %s" var2="y"; printf(temp,var2);
3
by: google | last post by:
Consider the following code: char str; char str2; strcpy(str, "%alfa% %beta% d%100%d %gamma% %delta%"); printf("printf: "); printf("1%s2", str); printf("\nsprintf: "); sprintf(str2, "1%s2",...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
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...
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,...

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.