Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hey guys I need to make an application using Qt that reads integers from a text file and creates a 2d plot from it. I figure that I need to transfer the integers from the txt file to an array but I am not sure how to do so.
The file has each integer on its own line. Any help will be appreciated.
Well reading a file line by line and put the contents into a vector shouldn't be that hard. Have a look at the QFile api docs. They have some basic examples there.
std::vector<int> here_are_your_ints;
QFile file("yourFileWithIntegers.txt");
// basic error checking
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
// read the contents line by line
while (!file.atEnd()) {
QByteArray line = file.readLine();
QDataStream ds(line);
int int_in_line = 0;
ds >> int_in_line;
here_are_your_ints.push_back(int_in_line);
}
Searching for a good plotting library? I am using QCustomPlot.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
This code asks the user for a colour (red,green or yellow) and turns the LED on.
However for some reason, it doesn't work. All the confitions turn out to be false even when i put the correct values (red ,yellow or green)
I don't know what the reason is for this code to not work...
enter code here
void loop() {
// put your main code here, to run repeatedly:
Serial.println(Msg1);
while(Serial.available()==0){}
Val=Serial.readString();
if (Val=="red") {
digitalWrite(redLed,HIGH);
digitalWrite(greenLed,LOW);
digitalWrite(yLed,LOW);
} else if (Val=="green"){
digitalWrite(redLed,LOW);
digitalWrite(greenLed,HIGH);
digitalWrite(yLed,LOW);
} else if (Val=="yellow") {
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(yLed,HIGH);
}
}
Adding Val.trim() after readString will remove whitespace and your program will run as expected.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to access a text file and read some of its contents to change them with a new value.
This Find and Replace is really helpful but my requirement is slightly different.
Say if these are my file contents
image.description=Template Image 08182015
image.version=1.3.111
baseline.name=001_08_18_2015
I want to change them to
image.description=Template Image 08192015 #19 instead of 18
image.version=1.3.112 #112 instead of 111
baseline.name=001_08_19_2015 #19 instead of 18
At any point of time I will not be knowing what is the value of each variable but all I know is the variable name like "Image version" So now I need some script to find what is the value of variable image.version and auto increment the value to the next possible integer.
Any suggestions/ thoughts?
With GNU awk for the 3rd arg to match():
$ awk 'match($0,/(image\.version.*\.)(.*)/,a){$0=a[1] a[2]+1} 1' file
image.description=Template Image 08182015
image.version=1.3.112
baseline.name=001_08_18_2015
For the others since no arithmetic is involved you should be able to just use gensub() similarly.
Or, maybe this is the kind of thing you're looking for:
$ cat tst.awk
BEGIN { FS=OFS="=" }
$1=="image.description" { match($2,/.* ../); $2=substr($2,1,RLENGTH) substr($2,1+RLENGTH,2)+1 substr($2,3+RLENGTH) }
$1=="image.version" { match($2,/.*\./); $2=substr($2,1,RLENGTH) substr($2,1+RLENGTH)+1 }
$1=="baseline.name" { split($2,a,/_/); $2=a[1]"_"a[2]"_"a[3]+1"_"a[4] }
{ print }
$ awk -f tst.awk file
image.description=Template Image 08192015
image.version=1.3.112
baseline.name=001_08_19_2015
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I'm trying to setup a script that executes a file that is downloaded from a URL.
At the moment, I have this code, which will just launch default browser, then access the URL typed into an input box (which then results in the download starting).
$inputBox = GUICtrlRead($downloadsURL)
ShellExecute($inputBox)
The file is currently being downloaded to the current logged in users "Downloads" directory (Windows Box).
What would be a "robust" solution for executing the downloaded file?
The filename changes often... would there be a way to rename the downloaded file?
Or maybe ensure I have a "clean" Downloads directory first, then have autoit automatically execute whatever file is in the directory after running the script?
You should always clean up your original download files. Leaving wasted space isn't fare to the end user.
You haven't really given us much to go on. GUICtrlRead simply means you're reading a control (I assume an Input box). And if that's the URL, then I would suggest using InetGet() to download the file to a specific place, then use Run or ShellExecute to run the file (if that's the kind of file that needs to be run that way).
So it might look this way:
Global $gszDir = #DocumentsCommonDir
Global $gszFileName = "mydownloadfile.exe"
Global $gszURL = "URL To File To Download"
_DownloadAndRemoveOriginal($gszURL, $gszDir, $gszFileName)
If #error Then
MsgBox(16 + 262144, "Error", "Error downloading: " & #error)
Exit 1
EndIf
Func _DownloadAndRemoveOriginal($szURL, $szDirectory, $szFileName)
; remove old downloaded file
Local $szFullPath = $szDirectory & "\" & $szFileName
If FileExists($szFullPath) Then
FileDelete($szFullPath)
EndIf
; download and wait for download to complete
Local $iGet = InetGet($szURL, $szFullPath, 1, 0)
If Not $iGet Then
; failed
Return SetError(1, 0, 0)
EndIf
Local $iRet = ShellExecute($szFullPath)
Return SetError(0, 0, $iRet)
EndFunc
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I know this may sound a little stupid, but one of my NGINX config files is a piece of crap when it comes to formatting. It works and all but that's about it.
I tried to find some kind of beautifier or formatter, like http://jsbeautifier.org/ but then for nginx config files instead of javascript, but no luck so far.
I hope anyone would have a suggestion. There are no requirements, as long as it can format quickly / lazily made NGINX config files!
Thanks!
I found a few projects which might suit your needs:
Nginx Formatter (python) by 1connect
you can get it here
Nginx beautifier (js/nodejs) by vasilevich
nginxbeautifier.com which lets you format configs quickly in a web browser.
you can get a command line tool also on the same site to run it locally.
If your block lines end with {'s and }'s, this simple indenter could help you a bit.
It does not format all your configs, it only fixes indentation.
Original in awk (source):
#!/usr/bin/awk -f
{sub(/^[ \t]+/,"");idx=0}
/\{/{ctx++;idx=1}
/\}/{ctx--}
{id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0}
Or rewritten in python:
INDENT = ' ' * 4
def indent(contents):
lines = map(str.strip, contents.splitlines())
current_indent = 0
for index,line in enumerate(lines):
if (line.endswith('}')):
current_indent -= 1
lines[index] = current_indent * INDENT + line
if (line.endswith('{')):
current_indent += 1
return ('\n').join(lines)
There is a fork of http://jsbeautifier.org/ for nginx here: https://github.com/vasilevich/nginxbeautifier
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have to rename a list of files in a folder so that:
From file named:
> myfile_000.txt
> myfile_001.txt
> ......
to file named:
> myfile_1.txt
> myfile_2.txt
> .......
Total files = 156
I used the following script:
> file.rename(list.files(pattern="myfile_*.txt", paste0("myfile_", 1:156)))
But without success.
Error:
Error in file.rename(list.files(pattern = "myfile_*.txt", paste0("myfile_", :
argument "to" is missing, with no default
The error message tells you, that you didn't specify the new names. It should work if you change the position of one ):
file.rename(list.files(pattern="myfile_*.txt"), paste0("myfile_", 1:156))