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

What is the Correction Required?

Dear All,

I have line of code

fprintf(Fp_write, "%x", *Data++);

Data is char *,

The problem in the above line of code

its says that data is char but you print in the file with binary mode
i.e "%x", this x is unsigned int.... so when we print in the file
we get the extra field as the ffffff as the prefix on most of the
data.

I can understand this problem as I am trying to take the char pointer
value but forcing the compiler to print in the unsigned int format
i.e (%x)... But I dont know how to fix ? as i only want to print
the char data into the binary.

any idea and pointer to this

Thanks In Advance.
Ranjeet

Nov 15 '05 #1
4 1165
ra***********@gmail.com wrote on 15/07/05 :
fprintf(Fp_write, "%x", *Data++);
It's not recommended to use a unary operator in a parameter. The result
is implementation-dependent, and the semantic is unclear...

Prefer

fprintf (Fp_write, "%x", *Data);
Data++;
Data is char *,


If so, there is a type problem. "%x" is expecting an unsigned int. Note
also that a char could be signed (it's implementation-dependent). To
have it right, I suggest :

fprintf (Fp_write, "%x", (unsigned) (unsigned char) *Data);
Data++;

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++

Nov 15 '05 #2


Emmanuel Delahaye wrote:
ra***********@gmail.com wrote on 15/07/05 :
fprintf(Fp_write, "%x", *Data++);
It's not recommended to use a unary operator in a parameter. The result
is implementation-dependent, and the semantic is unclear...

Prefer

fprintf (Fp_write, "%x", *Data);
Data++;
Data is char *,


If so, there is a type problem. "%x" is expecting an unsigned int. Note
also that a char could be signed (it's implementation-dependent). To
have it right, I suggest :

fprintf (Fp_write, "%x", (unsigned) (unsigned char) *Data);
Data++;


Thanks Emmanuel you cleared my issue, Thanks
Ranjeet
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++


Nov 15 '05 #3
Hello Emmanuel,

Emmanuel Delahaye <em***@YOURBRAnoos.fr> wrote:
ra***********@gmail.com wrote on 15/07/05 :
fprintf(Fp_write, "%x", *Data++);


It's not recommended to use a unary operator in a parameter. The result
is implementation-dependent, and the semantic is unclear...

Prefer
fprintf (Fp_write, "%x", *Data);
Data++;


Can you please elaborate where the problem is in this construction of
the OP? I do not see any problem in it as long as fprintf() is not a
makro. As Data is not used more than once in this line, it seems
well-defined to me.

Regards,
Spiro.
Nov 15 '05 #4
Spiro Trikaliotis wrote:
Hello Emmanuel,

Emmanuel Delahaye <em***@YOURBRAnoos.fr> wrote:
ra***********@gmail.com wrote on 15/07/05 :
fprintf(Fp_write, "%x", *Data++);


It's not recommended to use a unary operator in a parameter. The result
is implementation-dependent, and the semantic is unclear...

Prefer
fprintf (Fp_write, "%x", *Data);
Data++;


Can you please elaborate where the problem is in this construction of
the OP? I do not see any problem in it as long as fprintf() is not a
makro. As Data is not used more than once in this line, it seems
well-defined to me.


*Data++ is indeed well-defined, and a well-known idiom. I think Emmanuel was
concerned that the OP was not using "good style", although I think on this
occasion there wasn't anything wrong with it. We are, after all, supposed
to be writing C, not BASIC.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #5

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

Similar topics

14
by: Oleg | last post by:
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two...
9
by: developer | last post by:
Does anyone know what is the way IE treats span tags(<span>) and table tags(<tr>, <td>)? Should the <span> tag be encolsed in tds and trs if it placed with other elements that are in a table? Can...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
24
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
39
by: VidTheKid | last post by:
THE PROBLEM The % symbol is too vague when defining dimensions in CSS and HTML. It can relate to an inherited value, a measure of the containing element (which can differ between box models) or...
10
by: ben | last post by:
is there anyway in c to write code that can variably make use of one of two structs (one that has 32 bit vals and the other that has 64 bit vals) throughout the code? i'm writing some code that...
36
by: Jules | last post by:
All, how do I describe a string consisting of any number of characters, with an optional (but unique when occuring) end-of-line expression '/'? With groups if possible, as in...
9
by: fishmonger1972 | last post by:
I'm a librarian trying to put a finishing touch on an online materials catalog. The line below seems to do nothing in my program.. And I don't get any error messages. So, I'm very perplexed...
7
by: =?Utf-8?B?UHJpdmF0ZQ==?= | last post by:
Hey, Can some one tell me about what's wrong with the following code and what is the solution with some meaningful correction ----------------------------- class Program { static void...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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: 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
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
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...

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.