Here is my code below, it doesn't printf. But I step it thru using the for
statement and use putchar to the display, its there...
How can I get it to use printf? If the problem is needing a null at the end
and how can I do this?
I tried pos='\0' after my last memcpy and that doesn't work either.
=============== =============== =============== =============== =
void ERR(char * err_msg){
char tmp[1024],*pos;
unsigned int len,i,s;
memset(tmp,'\0' ,1024);
len=strlen(err_ msg);
s = ntohl(len);
pos=tmp;
memcpy(pos,&s,s izeof(s));
pos+=sizeof(s);
memcpy(pos,err_ msg,len);
printf("%s\n",t mp);
}
Nov 14 '05
11 1830
jt wrote: void ERR(const char *err_msg) { printf("%2x %s\n", (unsigned long)strlen(err _msg), err_msg); {
That is good, but we are not quite there of what I need to accomplish.
This is what printf prints: 2Athis is a test for the err messages to cad (that good and we are getting somewhere not)
The client will read it in binary hex and you see that the 1st 4 bytes (32 61): 32 61 74 68 78 20 and so on .... would be a very large decimal.
note: my requirement is that fist four bytes should be in network byte order and read as 00 2A ..... in binary hex. Not ascii as above.
I tried everything and it always comes out in ascii as you have it as well.
You need something like this:
unsigned long len = strlen(err_msg) ;
printf ("%c%c%c%c%s ",
(int)(len >> 24),
(int)((len >> 16) & 0xFF),
(int)((len >> 8) & 0xFF),
(int)(len & 0xFF),
err_msg);
--
Eric Sosman es*****@acm-dot-org.invalid
On Sun, 12 Jun 2005 07:01:31 GMT, Martin Ambuhl
<ma*****@earthl ink.net> wrote: jt wrote: s = ntohl(len);
ntohl is not a standard C function (which makes it off-topic here); it isn't even a standard POSIX function (which makes it off-topic in even more places). <snip>
It is POSIX now, as of 2001/2002 = SUS3. Still not standard C.
- David.Thompson1 at worldnet.att.ne t This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: drj0nson |
last post by:
Without getting too mathematical : how do you print/handle big numbers?
for ( int i = 1 ; i < 10 ; i ++)
cout << (123456789 << i) << endl;
246913578
493827156
987654312
1975308624
-344350048
|
by: Kit |
last post by:
Hey there, and thanks for reading a newbie post. I have a lex
assignment in which we are supposed to grab strings from a C source
file, and print them out to the screen, with escaped characters
"converted". Here's part of the assignment text:
----------------------------------------------------------------
Example:
main() {
char *s = "This is string one";
|
by: Maxime Barbeau |
last post by:
Hi.
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);
my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)
Is there any formtat I can use? %08uX ?
|
by: teachtiro |
last post by:
Hi,
'C' says \ is the escape character to be used when characters are
to be interpreted in an uncommon sense, e.g. \t usage in printf(),
but for printing % through printf(), i have read that %% should be used.
Wouldn't it have been better (from design perspective) if the same
escape character had been used in this case too.
Forgive me for posting without verfying things with any standard
compiler, i don't have the means for now.
|
by: Ross |
last post by:
I have a quick question regarding printing string constants. When you
printf() a string constant, how are the characters encoded that get
sent to the standard output? Is it in the execution character set?
Thanks in advance.
| |
by: Robert Seacord |
last post by:
i am trying to print the address of a function without getting a
compiler warning (i am compiling with gcc with alot of flags).
if i try this:
printf("%p", f);
i get:
warning: format %p expects type 'void *; but argument 2 has type 'void
|
by: Pedro Pinto |
last post by:
Hi there!
I'm creating a function that copies some information to a buffer and
enters a delimiter string "//" between results.
My issue here is when i print the buffer it appears this weird result:
cod : 2
id : 20
Buffer is
|
by: Mukesh_Singh_Nick |
last post by:
I am practicing printf formatting options. I want to print out a
string literal as a raw string as opposed to its special meaning. For
e.g I want to print out the "%f" part in:
printf("%f\n");
literally as "%f" rather than a zero value floating point/constant
double (0.000000).
I tried to escape the % sign but the compiler complained with a
|
by: trkrbabe |
last post by:
Hi, this is my first time posting here. It appears that I am taking the same class as a few other people here. I have only been learning Java for about five weeks now.
I have my Product class compiled and I finally got my Inventory class compiled but when I run the program it prints the first line correctly then I input the item name but then it prints the next two lines when it should print one and allow me to input then print the next.
...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |