I want to know the source code: how can I create multiple directories using Turbo C++. For example, you can see in MS-DOS, in a single line:
md a b c d
creates a, b, c, and d directories simultaneously.
I have used this code in Turbo C++ (Borland Compiler 5.5):
char dir_name[256];
int status=mkdir(dir_name);
if(status==0)
{
cout<<"Directory created.";
}
else
{
cout<<"Error!";
}
Can anybody help me out, please...?
You can store the names in a 2-day array the names can be entered in a single line by delimiting them using space and then using a loop create directories till you reach the end of your array.
Related
I have these lines of code in one program:
source("R:/ML NC8 MENSAL.R")
source("R:/ ML NPC NC8 MENSAL.R")
The mentioned programs both have these lines of code:
# Defining Variable
MONTH <- "01_2021"
I want to make this definition in the first program for the two programs.
Which code should I write?
Thank you for your help.
If both scripts have these lines and you only want to return it from the first script, then I would write a function in both scripts. Only the first one would return the month-value.
month_return_scr1 <- function(){
MONTH <- "01_2021"
#more code
return(list(MONTH, more variables, or data.frames)}
month_return_scr2 <- function(){
MONTH <- "01_2021"
#more code
return(list(more variables, or data.frames)}
The Month would then not be returned by the second source.
I used successfully the following solution:
Create a program - R:/constants.R - with the month variable (and any
others used in all programs)
Create a program - R:/superprogram.R - that executes all the 23 programs
In each 23 programs replace the variables definition for this code
source("R:/constants.R"). This will bring the constants defined in
the source file into the global environment.
Change the variables in program R:/constants.R and save it
Run R:/superprogram.R
I am working on a big (~500Mb) RAW txt file.
There are about 20,000,000 lines in the file.
Each line includes one double and one int. For example:
45782.1234852 10
Below is my simple code:
QTextStream rdStream(&qFile_Input);
while (!rdStream.atEnd())
{
//QStringList qList_data=rdStream.readLine().split(" ",QString::SkipEmptyParts);
rdStream.readLine();
}
It takes about 30 seconds just to read line QTextStream::readLine();
If I add .split(" ",QString::SkipEmptyParts) into a Qstringlist, then the total time required jumps to 5 minutes. My question is three fold:
Where does the time gap comes from?
Is there a way to get a shorter processing time?
If my file is larger than the RAM of PC, will I encounter an
error? If so, what can I do?
Thanks in advance!
Well, it seems that the splitting part adds an enormous overhead time-wise. Instead of using the Qt class QTextStream, you could probably just use the methods from the c++ standard library. You should get better performance than the 5 minutes you are seeing now.
#include <fstream>
int main()
{
std::ifstream infile("thefile.txt");
double a;
int b;
while(infile >> a >> b)
{
//Do something with a and b here, they've been read
}
return 0;
}
I have a script in which I call R and depending on the directory I specify I want it to carry out a different process. One directory starts with L and the other with S. I have numerous directories that either start with L or S and they all end differently.
I specify the directory in bash and run a script like so:
./script L_dir
or
./script S_dir
So within my R script I have it set up as such:
args <- commandArgs(TRUE)
img_dir <- args[1]
if(img_dir == "^L*"){
do_process_1
} else {
do_process_2
}
Everything works fine except that no matter what directory I specify, the process called will always be do_process_2.
I have looked at this question and tried to adapt it but can't get it to work.
After changing my code to
if(grepl("^LM*", img_dir)){
do_process_1
} else {
do_process_2
}
it worked. Be careful if you change it to the above and it still carries out process_2. This may be because what you are looking for, in my case ^L*, may also be in your second directory name i.e. dir_L = LMNOP, dir_S = STUVLJH. But once i specified ^LM* it did what i wanted it to do.
I'm trying to read and edit a Desktop Entry .desktop file using Qt QSettings. The problem is that these files contain keys with multiple values separated by semicolon ;. I tried reading these as QStringList but no luck. I only get the first value. For example:
Keywords=disc;cdrom;dvd;burn;audio;video;
Categories=GTK;GNOME;AudioVideo;Audio;Video;DiscBurning;
MimeType=application/x-cd-image;application/x-cdrdao-toc;application/x-cue;application/x-toc;audio/x-scpls;audio/x-ms-asx;audio/x-mp3-playlist;audio/x-mpegurl;application/x-brasero;x-content/audio-cdda;x-content/video-dvd;x-content/video-vcd;x-content/video-svcd;x-content/image-picturecd;
Getting the values with:
settings.value("Desktop Entry/MimeType").toStringList();
settings.value("Desktop Entry/MimeType").toString();
returns only the first value (in my example: disc, GTK or application/x-cd-image).
How to I return the full value from those keys? And how do I write it back using QSettings?
Update (first attempt was completely useless)
Variant 1
QMap<QString, QString> settings;
QFile inFile("<input filename.ini>");
if(inFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inFile);
while (!in.atEnd())
{
QString line = in.readLine();
QStringList linelist = line.split("=");
settings[linelist[0]] = linelist[1];
}
}
Variant 2
use QSettings::registerFormat().
This is probably the only "clean" way to do it with QSettings. The advantage is that you can register it with the .desktop extension. You'll have to write a pair of ReadFunc() and WriteFunc() functions.
I think you can't do it. QSettings has certain interpretation of .ini file format, which is very close to Windows interpretation, and is not meant for generic parsing. Semicolon starts a comment, and apparently QSettings allows comment after value until end of line, and AFAIK there's no way around it.
You need to find a different library to handle .desktop files, or implement one yourself.
How can I diff 2 files so that:
I do not care about any kind of white space (-b option)
I do not care about position of content. ( ?? )
What I mean by 2 above is: file with a on line1 and b on line2 is equal to another file with b on line1 and a on line2.
Please let me know if the question is still not clear.
thanks.
Sort the two files first, then diff them. There's no way to convince diff that the a and b lines are in any way interchangeable. Order is extremely important to diff.
Edit for comment -
Tools like diff do not understand any higher level semantics beyond simply ordered lines. You might try writing a tool that converts your files in to those higher level concepts, one per line, that perhaps diff can then process (vs writing a custom diff, which is kind of a pain). Since you can't sort the entire file, perhaps you sort those small sections where "order doesn't matter", that way they won't matter to diff as well.
The final file doesn't have to necessarily be a proper file format (i.e. compatible with the original syntax), rather simply enough to convey to use the differences you're looking for while still capturing the semantics your after while also leveraging an off the shelf tool like diff.
Example:
File 1:
block thing {
a
b
}
block thing 2 {
c
d
}
File 2:
block thing {
b
c
a
}
block thing 3 {
f
e
}
"sorted" File 1:
block thing {
a
b
}
block thing 2 {
c
d
}
"sorted" File 2:
block thing {
a
b
c
}
block thing 3 {
e
f
}
In the end, ideally, you'll find that Block 3 is "new" as well as the "c" in Block 1.