473,396 Members | 2,098 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.

printf ultra-fast question

Hi,

Perhaps a stupid question but I wonder if this isn't possible using C:

printf("\nOr push <enter> for default (which is theta=%ld)%s", theta, ": ");
It would be nicer to have it on one line... (I know this works):

printf("\nOr push <enter> for default (which is theta=%ld)", theta);
printf(": ");*/
Compiler: MS Visual studio 2005. The compiler doesn't complain actually
(well, at least not about the particular line). But when I run the
program VS2005 opens a window named "Visual Studio Just-In-Time
Debugger" and then it wants me to choose between two possible debuggers
(1: New instance of VS 2005, 2: My project). I then tell it that I don't
want to debug the program just stops. If I instead tell it that I want
to debug it, it says: "Unhandled exception at 0x10227.... (msvcr80d.dll)
Access violation reading...

What is wrong?
Med venlig hilsen / Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
Feb 14 '06 #1
7 2805
Martin Jørgensen wrote:
Perhaps a stupid question but I wonder if this isn't possible using C:

printf("\nOr push <enter> for default (which is theta=%ld)%s", theta, ":
");
It would be nicer to have it on one line... (I know this works):

printf("\nOr push <enter> for default (which is theta=%ld)", theta);
printf(": ");*/
Compiler: MS Visual studio 2005. The compiler doesn't complain actually
(well, at least not about the particular line). But when I run the
program VS2005 opens a window named "Visual Studio Just-In-Time
Debugger" and then it wants me to choose between two possible debuggers
(1: New instance of VS 2005, 2: My project). I then tell it that I don't
want to debug the program just stops. If I instead tell it that I want
to debug it, it says: "Unhandled exception at 0x10227.... (msvcr80d.dll)
Access violation reading...

What is wrong?


If I remember correctly you can just write the strings one after the
other like

"first string" "second string"

The compiler will turn it into a single string constant.
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Feb 14 '06 #2

Martin Jørgensen wrote:
Hi,

Perhaps a stupid question but I wonder if this isn't possible using C:

printf("\nOr push <enter> for default (which is theta=%ld)%s", theta, ": ");
It would be nicer to have it on one line... (I know this works):

printf("\nOr push <enter> for default (which is theta=%ld)", theta);
printf(": ");*/


Check type of "theta"?

Feb 14 '06 #3
Martin Jørgensen <un*********@spam.jay.net> writes:
Perhaps a stupid question but I wonder if this isn't possible using C:

printf("\nOr push <enter> for default (which is theta=%ld)%s", theta, ": ");
It would be nicer to have it on one line... (I know this works):

printf("\nOr push <enter> for default (which is theta=%ld)", theta);
printf(": ");*/
Compiler: MS Visual studio 2005. The compiler doesn't complain
actually (well, at least not about the particular line). But when I
run the program VS2005 opens a window named "Visual Studio
Just-In-Time Debugger" and then it wants me to choose between two
possible debuggers (1: New instance of VS 2005, 2: My project). I then
tell it that I don't want to debug the program just stops. If I
instead tell it that I want to debug it, it says: "Unhandled exception
at 0x10227.... (msvcr80d.dll) Access violation reading...

What is wrong?


What's wrong is that you're not giving us enough information. Post a
small complete compilable program that exhibits the problem.

Your first printf() statement should be equivalent to:

printf("\nOr push <enter> for default (which is theta=%ld): ", theta);

That should be ok *if* theta is of type (signed) long (though the
output might not appear immediately unless the printf() is follwwed by
fflush(stdout)).

Why are you putting the ": " in a separate argument? Since "%s" and
": " are both 2 characters long, it doesn't even save you any space in
your source.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 14 '06 #4
Martin Jxrgensen <un*********@spam.jay.net> writes:
Perhaps a stupid question but I wonder if this isn't possible using C:

printf("\nOr push <enter> for default (which is theta=%ld)%s", theta, ": ");


That's a strange invocation of printf(). I would write it like
this:
printf("\nOr push <enter> for default (which is theta=%ld): ", theta);

Also, as another poster commented, check that `theta' is really a
long int.
--
"I ran it on my DeathStation 9000 and demons flew out of my nose." --Kaz
Feb 14 '06 #5
Ben Pfaff wrote:
Martin Jxrgensen <un*********@spam.jay.net> writes:

Perhaps a stupid question but I wonder if this isn't possible using C:

printf("\nOr push <enter> for default (which is theta=%ld)%s", theta, ": ");

That's a strange invocation of printf(). I would write it like
this:
printf("\nOr push <enter> for default (which is theta=%ld): ", theta);

Also, as another poster commented, check that `theta' is really a
long int.


Aah, stupid mistake. theta was double, so the following works:

printf("\nOr push <enter> for default (which is theta=%g)%s", theta, ": ");

That explains the strange behaviour from vs2005... Thanks everyone.
Med venlig hilsen / Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
Feb 14 '06 #6
Martin Jørgensen <un*********@spam.jay.net> writes:
Ben Pfaff wrote:

[...]
Also, as another poster commented, check that `theta' is really a
long int.


Aah, stupid mistake. theta was double, so the following works:

printf("\nOr push <enter> for default (which is theta=%g)%s", theta, ": ");

That explains the strange behaviour from vs2005... Thanks everyone.


Great -- but it still doesn't explain why you pass the ": " as a
separate argument, rather than the simpler:

printf("\nOr push <enter> for default (which is theta=%g): ", theta);

My guess is that it's a random change you made while trying to track
down the problem. Now would be a good time to back it out.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 15 '06 #7
Keith Thompson wrote:
-snip-
Great -- but it still doesn't explain why you pass the ": " as a
separate argument, rather than the simpler:

printf("\nOr push <enter> for default (which is theta=%g): ", theta);

My guess is that it's a random change you made while trying to track
down the problem. Now would be a good time to back it out.


Ah, I see... Actually I think I did it that way because that is how I
did some matlab programs for some months ago... Don't know if matlab
understands printf("\nOr push <enter> for default (which is theta=%g):
", theta);, but perhaps you're right...

Yeah, you're right. I should change the line... I'll do that tomorrow.
Gotta get some sleep now. It must be a bad habit or something, but the
important thing is that both methods work :-)
Med venlig hilsen / Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
Feb 15 '06 #8

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

Similar topics

7
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 %%...
0
by: Michael D. Reed | last post by:
I have a C++ program that I am trying to get to compile and link in VS2003. It is an old windows program that was built and maintained with older versions of VS and VC++. I made the necessary...
5
by: sam | last post by:
hi all, i continue to footle around on my spanking new ultra 20 (1.8GHz / Opteron Model 144), gradually trying to get to grips with python and unix both. the slow print time in IDLE had...
2
by: zafar | last post by:
in table i have a field for date and time, but in grid only date is shown, where i want to display the time only ( i am using ultra grid tool of infragestrics),, thanx if any body can help me for...
3
by: Sarahb1337 | last post by:
Hi all, I have two tables that I'm trying to display in a Master Detail fashion in an Infragistics UltraGrid. I added both tables to a dataset and added a datarelation between the two tables...
15
by: CMOS | last post by:
one of the projects im working in currently requires use of ultra large sized maps, lists, vector, etc. (basically stl containers). Sizes might grow up to 1000 Million entries. since it is...
12
by: naunetr | last post by:
in program below #include <stdio.h> int main() { int id = 123, io = 0123, ih = 0x123; long ld = 1234567L, lo = 01234567l, lh = 0X1234567L; float f = 123.456f; double d = 01234.56789L;
0
by: faizalahmd | last post by:
I would like to have paging as well as sorting in a infragistics ultra web grid control .. regards, Faizal Ahmed
0
by: bwljgbwn | last post by:
nero 7 ultra edition crack http://cracks.12w.net F R E E
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.