Hello all, I want to open multiple txt files with similar names in C++
I have attempted this with the following code -
//Create as many txt files as there are valid propagation constants
-
//Propagation constants are elements of the vector beta
-
for(int j=0;j<(int)(number_of_nodes);j++){
-
if(*(beta+j)>substrate*k && *(beta+i)<core*k){
-
FILE *p_j;
-
p_j=fopen("c:\\data_j.txt","w");
-
}
-
}
-
The idea is that I would open a set of txt files data_1, data_2, data_3....etc
so that I can send data to each of these txt files later.
The code as it stands doesn't work. It just opens a single txt file called data_j.txt
Can anyojne tell me how to do it so it creates multiple files with different file names?
3 5713 - #include <stdio.h>
-
#include <conio.h>
-
#include <string.h>
-
int main()
-
{
-
char a[10]="d:\\a1.txt";
-
FILE *fp;
-
int j;
-
for(j=65;j<=90;j++)
-
{
-
a[5]=j;
-
-
fp=fopen(a,"w");
-
fprintf(fp,"My program");
-
fclose(fp);
-
-
-
j++;
-
}
-
-
return 0;
-
}
This is the one way to create no of files....
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char a[10]="d:\\a1.txt ";
FILE *fp;
int j;
for(j=65;j<=90; j++)
{
a[5]=j;
fp=fopen(a,"w") ;
fprintf(fp,"My program");
fclose(fp);
j++;
}
return 0;
}
How does this work?
Ganon11 3,652
Recognized Expert Specialist
Hello all, I want to open multiple txt files with similar names in C++
I have attempted this with the following code -
//Create as many txt files as there are valid propagation constants
-
//Propagation constants are elements of the vector beta
-
for(int j=0;j<(int)(number_of_nodes);j++){
-
if(*(beta+j)>substrate*k && *(beta+i)<core*k){
-
FILE *p_j;
-
p_j=fopen("c:\\data_j.txt","w");
-
}
-
}
-
The idea is that I would open a set of txt files data_1, data_2, data_3....etc
so that I can send data to each of these txt files later.
The code as it stands doesn't work. It just opens a single txt file called data_j.txt
Can anyojne tell me how to do it so it creates multiple files with different file names?
Instead of using j directly inside the string, you will have to create the string manually. You can add the following two statements: - char* filename = "c:\\data_X.txt";
-
filename[8] = j; // the X is at position 8
to your loop to create the filename - then use - p_j=fopen(filename, "w");
You may have to create the array using some different method (like malloc), but I'm not experienced with these methods.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Evan Kontos |
last post by:
I am using the window.open function to open a small window and I am
using GET to get values back from that window. I want to be able to open
another from the second window but I get an error message when I try to
do another window.open. Any suggestions are welcomed.
Evan Kontos | EKontos@comtekcadd.com
27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295...
|
by: SenthilVel |
last post by:
HI all
in my visual studio DOtnet .
i am not able to open multiple cs files in the projects , its openings only
one cs file at a time,
can any one let me know, what setttings i must do in order to get all the CS
files to edit so that i can see all the files opened.
Thanks
Senthil
|
by: vinX |
last post by:
Ok, i am making a file renaming utility, you can add filesize (in MB o
KB), filepath, creation date and/or time, a counter, parent folder, th
original name etc...
I put the program in the (registry: *.*\shell\myprogram\command(valu
of the comand key is "...\myprogram.exe" "%1") context menu, so tha
when you select multiple files, the paths would be passed to th
program.
First i was having problems with multiple instances of my program, an...
|
by: Arun |
last post by:
Hi,
I have simple question to ask. How to write multiple Binary files to the
Browser using Asp.Net and Visual C#.net
I have seen examples where single binary file is written to browser.
-Regards
Arun
|
by: Ryan Malone |
last post by:
I have a situation where I need to download multiple files in a vb.net
application.
To speed up the process, I am trying to download multiple files at one
time looping through each of the files and launching them in their own
thread (code below). The problem is that when there are hundreds of
files to download, it launches them all at the same time and half
don't get downloaded. Any idea how I could control it to launch say 4
at a time,...
| |
by: chaossliver |
last post by:
I'm a brand new scripter, and as such, I have very poor experience in
coding.
I have been looking around at some open source codes written in pure C
and was wondering if anyone knew of a program that could convert
standard C files into files visible with a Visual C++ editor, such as
Microsoft's program.
--Bryan
|
by: Ronin |
last post by:
Hi guys,
I have a problem regarding a txt file operations.I have a listbox which has
various 3 digits numbers.there are 2 txtboxes on my form .now suppose if
check 101 from check box and write 1 and 7 in txtboxes i should be able to open all the files having the numbe 10117.
to inform u guys the files are txtfiles having names
10117051
where101 is market no 17 is the year and 05 is week and 1to 7 may be day
|
by: ahammad |
last post by:
I want to be able to select mutliple files from a standard File Open dialog box, and be able to open all those files simultaneously.
How can this be done? Is there a specific flag that you can use in the CFileDialog class constructor?
This is how I've been doing it, but just for one file:
CFileDialog FileDlg(TRUE, _T("*.txt"), NULL, 0, _T("Text Files (*.txt)|*.txt|" ));
Thanks
|
by: kimiraikkonen |
last post by:
Hi,
I have an app which has a listbox and when i double click an
associated fileS, i want their paths to be added into listbox in my
application.
This code works good when i try to open a "single" file with my app
which works to get commandline arguments to get file paths:
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length 1 Then
|
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: 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: 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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |