Hi,
I would like to save data from multiple repetitive simulations into a
set of files. Each time a simulation restarts, I would like it to
automatically generate a file with a name containing some of the useful
variable information.
For example, if M is 5 and N is 10, I want the file to be named as
"myfile-5x10.txt". How can I do this?
I guess I need to construct a string somehow and let it be my filename.
Thank you 8 17718
bobrics wrote: Hi,
I would like to save data from multiple repetitive simulations into a set of files. Each time a simulation restarts, I would like it to automatically generate a file with a name containing some of the useful variable information. For example, if M is 5 and N is 10, I want the file to be named as "myfile-5x10.txt". How can I do this?
I guess I need to construct a string somehow and let it be my filename.
Declare a character array to contain your file name. The array should
be big enough to contain the longest filename you would generate.
Then google for sprintf and read the documentation.
HTH
Thank you for the fast reply.
"bobrics" <bo*****@gmail. com> wrote:
# Hi,
#
# I would like to save data from multiple repetitive simulations into a
# set of files. Each time a simulation restarts, I would like it to
# automatically generate a file with a name containing some of the useful
# variable information.
# For example, if M is 5 and N is 10, I want the file to be named as
# "myfile-5x10.txt". How can I do this?
char format[] = "myfile-%dx%d.txt";
char filename[sizeof format+100];
sprintf(filenam e,format,M,N);
FILE *file = fopen(filename, "w");
--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
thank you,
this is interesting to know as well
bobrics wrote: thank you,
this is interesting to know as well
What is?
Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
SM Ryan wrote: "bobrics" <bo*****@gmail. com> wrote: # Hi, # # I would like to save data from multiple repetitive simulations into a # set of files. Each time a simulation restarts, I would like it to # automatically generate a file with a name containing some of the useful # variable information. # For example, if M is 5 and N is 10, I want the file to be named as # "myfile-5x10.txt". How can I do this?
char format[] = "myfile-%dx%d.txt";
Why make this a char[] instead of a const char *?
char filename[sizeof format+100];
Oh, it's so you can use sizeof? You could instead use a #define of
format as a string literal, then sizeof would work. I doubt there would
be any compilers that are brain-dead enough to then put two copies of
the literal into the executable, instead of making them share one memory
space!
sprintf(filenam e,format,M,N); FILE *file = fopen(filename, "w");
Or, considering that you are using a C99 feature already (a declaration
after an executable statement), you could use strlen() to define a VLA :-)
--
Simon.
On 2005-11-15, Simon Biber <ne**@ralmin.cc > wrote: SM Ryan wrote: "bobrics" <bo*****@gmail. com> wrote: # Hi, # # I would like to save data from multiple repetitive simulations into a # set of files. Each time a simulation restarts, I would like it to # automatically generate a file with a name containing some of the useful # variable information. # For example, if M is 5 and N is 10, I want the file to be named as # "myfile-5x10.txt". How can I do this?
char format[] = "myfile-%dx%d.txt";
Why make this a char[] instead of a const char *?
char filename[sizeof format+100];
Oh, it's so you can use sizeof? You could instead use a #define of format as a string literal, then sizeof would work. I doubt there would be any compilers that are brain-dead enough to then put two copies of the literal into the executable, instead of making them share one memory space!
The operand of sizeof wouldn't need to exist in memory anyway.
I believe it's legal to sizeof a "dereferenc ed" uninitialized pointer
e.g. as commonly recommended, x = malloc(sizeof *x)
On Tue, 15 Nov 2005 03:45:31 +0000 (UTC), in comp.lang.c , Jordan Abel
<jm****@purdue. edu> wrote: I believe it's legal to sizeof a "dereferenc ed" uninitialized pointer
e.g. as commonly recommended, x = malloc(sizeof *x)
This is determining the size of the type the pointer points to, it
never looks at the uninitialised pointer.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Xerxes |
last post by:
Hi,
I want to open a file for debugging purposes and want to know how I can
access it (write to it) from across multiple php files. I want to be
able to write debugging information from within multiple php files. Can
I store the file locally or does it have to be on the server? My php
files are a web hosting company's server.
I tried to store the file pointer returned by fopen as a session
variable. I get a warning: fopen...
|
by: Bill |
last post by:
For my personal use I am accessing a railway timetable page, parsing its
contents and then sending brief relevant information as the subject line of
an email to be read on a mobile phone.
The problem comes when I try to parse a second page, the url of which, I
have derived from an initial page.
I cannot go directly to the second (target) page but from the initial page
derive the url and put it in a string called $strTarget
In one...
|
by: huguogang |
last post by:
Just curious, any one know what the 3 part parameter "class CString
filename" would mean.
The code:
int TestFunc(class CString filename)
{
fopen(filename, "w");
}
Compile using Visaul C++, there is no complain about the defintion. But
|
by: Srikanth Ram |
last post by:
Hi,
I'm creating a PHP application. In this I am creating files in which the data will be stored date wise.
I wanted to create this filename with the system date. The system date is stored in a variable $Date.
fopen("/C/files/acceptedinfo.csv", "a+")
I tried
fopen("/C/files/acceptedinfo".$Date.".csv", "a+") and also
|
by: markmcgookin |
last post by:
Hi,
I know this is a common issue, but to be honest all the sites I find with solutions to this dont explain it well at all.
I have a variable ($fileName) which I want to add to
http://tempuri.org/
then attach .xsd to the end
| |
by: Tony Bansten |
last post by:
Assume I want to concatenate a literal text value and a variable value for a function parameter
then the following does NOT work:
objWorkbook.SaveAs("D:\work\v1_" + Filename)
The variable "Filename" is filled with a valid value.
So how do I otherwise concatenate two parts?
Tony
|
by: Autostrad |
last post by:
Below; I have 2 classes (forms), Namely, "PrintOneEmployee" and "DeleteOne". In class "PrintOneEmployee";
I want to declare a variable with name of "fileName" to contain the name of the file "Main\\_1Main.txt".
Later on, when I wanted to access the variable "fileName" in the other class, namely, "DeleteOne". The
compiler show an error that the variable is undeclared. What should I do to access the variable "fileName"
in the the...
|
by: piersvan |
last post by:
I have written a script to download a file from a website. But it only download about 700bytes --- less than 4kb. What am I doing wrong?
<?php
// block any attempt to the filesystem
if (isset($_GET) && basename($_GET) == $_GET) {
$filename = $_GET;
} else {
$filename = NULL;
}
|
by: IanJAl |
last post by:
I have a variable "fileName" = ****.pdb, where the *s are capitalised letters. After a method uses this variable as an argument, I need to change the extension part to .ent without changing the first part. For some reason, none of the str.replace methods seem to work.
|
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: 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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |