w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
In Linux launch a c program from Python handing the c program a large text string as an argument
You can pass it as an argument by just… passing it as an argument. Presumably you want to quote it rather than passing it as an arbitrary number of arguments that need to be escaped and so on, but that's easy with shlex.quote. For example: with open('bigfile.txt', 'rb') as infile: biginput = infile.read(2048) os.system('cprogram {}'.format(shlex.quote(biginput))) If you get an error about the argument or the command line being too long for the shell… then you can't do it. Python can't make the shell do things it can't do, and you refuse to go around the shell (I think because of a misunderstanding, but let's ignore that for the moment). So, you will need some other way to pass the data. But that doesn't mean you have to store it in a file. You can use the shell from subproces

Categories : Python

Perl Program to Read a Text File, Search for text within the File and copy the text to a new file
Why not awk? awk '/ Directory of /{at=$3;print;next}{print $0""FS""at}' your_file Perl: perl -lne 'if(/ Directory of (.*)/){$a=$1;print}else{$_.=" ".$a;print}' your_file if you want to do an inline replacement: perl -i -lne 'if(/ Directory of (.*)/){$a=$1;print}else{$_.=" ".$a;print}' your_file

Categories : Regex

Where is the text file once I publish the program?
Where is the file? it will be created on where your exe or dlls located. how can I make it write to a certain place? you can give full path to file location using (StreamWriter sw1 = new StreamWriter(Path.Combine(DirectoryPath, "DataNames.txt"),true)) { sw1.WriteLine(textBox1.Text); }

Categories : C#

How can I use a text file from the internet in my C program?
It is much more involved to get a web-resource than to read a file from disk, but you can absolutely do it, for example by using a library such as libcurl. An alternative strategy is to make components and tie them together with bash or other scripting. Your C program could for example read from standard input, and you could make a bash script something like this: curl http://www.ndbc.noaa.gov/data/realtime2/SPLL1.txt | ./the_program This way, you could keep your core C program simpler.

Categories : C

Deleting a line of text later in the program
According to this answer, you can print a backspace character using  in the console using System.out.print. Therefore, for however many characters you have previously printed, print that many backspace characters. Additionally, this answer for the same question suggests using the cls command to clear the console output entirely, however this forever binds your application to only operating systems that use that command (In this case Windows / Dos). In linux, for example, the command is clear...I'm sure you see the potential problem.

Categories : Java

text-wrapping program in c does not work correctly
You're never checking the value of i, yet it is indexing into your string array in the wrap function. Here is where the i value grows into the 1000's on my machine before crashing. I would recommend putting it on a debugger, simplifying your code, or at least check the variable that indexes into your string buffer to ensure it is not past the end of the buffer. HTH! EDIT Since you asked, I'll show you how I debugged this, just a little, on Ubuntu 12.04 LTS. From the shell, file called sotest.c # use the -g for debug info gcc -g sotest.c -o sotest # invoke the gnu debugger gdb sotest You'll see: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.h

Categories : C

Reading from a text file and then using the input with in the program
You can use std::getline function to get one line at a time. It looks like this: std::string strLine; int nCount = 0; while (std::getline(infile, strLine)) { stu_answers[nCount++] = strLine.at(0); } Then nCount will be the answer number.

Categories : C++

Reading from a text file and then using the input in the program
Have a look here. myfile.open(); if(!myfile.is_open()) { cout<<"Error opening output file"<<endl; system("pause"); return -1; }

Categories : C++

How to open a text file in notepad in a C program?
Given a file test.txt, you can display it in notepad on Windows with: #include <stdlib.h> int main () { system ("notepad test.txt"); return 0; } If you can be sure that your program will default to the cmd shell, you can just say system ("test.txt") and the file will open in whichever text editor is set as the default, but specifying the editor is safer because it deals with cases like the program being compiled under Cygwin, where the default shell will be sh, which doesn't open text files by default when you supply the filename at the command prompt. If you can't be sure your program will always be compiled on Windows then I would favour the ShellExecute() solution outlined by @Remy Lebeau. A program containing #include <shellapi.h> and a call to ShellExecute(

Categories : C

Text output sent to file and used later in the program. How to use buffer instead?
So, I think what you are looking for popen (or _popen in Windows), which will allow you to read the standard out from another process. You'd do something like FILE *fout = popen(micromegas.c_str(), "r"); instead of the system and fopen lines.

Categories : C++

Load from text file at program startup
If I understood you correctly, you want to pass the filename/names as commandline arguments? If you look at the Main, which starts the program you can se that it will store parameters in a string[] (string array) so if you pass arguments you can just check the args[] inside the program to get the parameters you sent in. Please ask more if you need more help! UPDATED As per your request if you open a file from windows explorer it will send the path of the file it to the Main method. So lets say you rigth click a file and choose to open it with your text editor. You have to use the path as I do below, and read the filecontents. Then you can do whatever you want with the content. class TestClass { static void Main(string[] args) { //Now you have all arguments in the s

Categories : C#

How to extract text with lxml in this scraper program?
that's because whatever you're looking for doesn't exist. Try the parents first. And then, once that works try this: owner[0].text If you can't find/remember which tr you want, just grab all the tds of the 3rd index: tree = html.fromstring(response.content) owner = tree.xpath('/html/body/div[2]/table[1]/tbody/tr/td[2]') texts = [o.text for o in owner] print texts Then, take your pick and modify code accordingly. Hope this helps.

Categories : Python

Cannot write the output to a text file in cpp program
You probably have the console input (scanf) confused with the file input (fscanf). The C-style functions for file I/O have an f prefix. See: fprintf, fscanf, fgets, and fputs.

Categories : C++

Error "UTF-8 Unicode C++ program text, with very long lines" and "ASCII English text, with very long lines"
These are not error messages in themselves, but output from the identification utility file. It's not good at recognizing different programming languages, and might think a C++ file is English or Java. "Very long lines" refers to the fact that the files have lines over 300 characters long. Both files are already UTF-8 (ASCII is a subset of UTF-8), and therefore don't need conversion (but you might prefer translating the line endings from to with dos2unix or tr -d ' '.

Categories : Linux

Error when Saving and writing text files while program is in jar
That’s the strangest thing I’ve seen for long: FileWriter fstream = new FileWriter(new File(".").getAbsolutePath()+File.separator+playerName + ".txt",true); getLogger().log(Level.INFO,"trying to save text document to " + new File("").getAbsolutePath()+File.separator+playerName + ".tct"); Try to clean up: File f=new File(playerName + ".txt"); FileWriter fstream = new FileWriter(f, true); getLogger().log(Level.INFO,"trying to save text document to " + f.getAbsolutePath()); Next thing: you should always close files after working with then. Then your file names do not match. One time it is playername+".txt" the next time it is just playername But the biggest mistake: Integer i = Integer.getInteger(reader.readLine()); return i.intValue(); Integer.getInteger does not parse the str

Categories : Java

How can I have my program read updates that it has just made to a text file?
The problem is here: fileobja.close … and a few similar lines. You're not calling the close method, you're just referencing it as a value. So, the file doesn't get closed, which means it doesn't get flushed, which means anything you've written to it may not be available to read yet. To fix it, just call the method: fileobja.close() As a side note, it's usually easier to use a with statement, which takes care of closing the file when you exit the block inside it. (It's like a magic try/finally.) Instead of this: f = open('foo', 'a') do_stuff(f) do_more_stuff(f) # ... f.close() Do this: with open('foo', 'a') as f: do_stuff(f) do_more_stuff(f) # ...

Categories : Python

How do I create a neat table-like layout in a basic text-only program?
See http://www.homeandlearn.co.uk/java/java_formatted_strings.html. It has (way) more examples than I can think off the top of my head.

Categories : Java

Program to write all the numbers divisible by 99 to a text file not working?
You need to open the file in write('w') mode: with open('blank.txt', 'w') as f: for num in range(99, 1000000001, 99): #do something here. Note that there's no need to close the file now, with statement will do that automatically for you.

Categories : Python

C# program to paste text from clipbord to any point where mouse clicks
You could just turn on some windows disability settings, If dragging or pasting is too awkward. If you really want to implement this, you need a global hook on the mouse so you can recieve mouse events from outside your application. See here or perhaps here. Then you have a problem, do you want to paste anywhere or just in address bars. First you'll have to define what an address bar window is and work out if that is what has the focus. Its a lot of effort and the behaviour is not especially desirable. If you really want this, please expand your question and improve its readability so that this post will be useful to future visitors.

Categories : C#

How to write a C++ program to erase text file when number of lines is > 30
Can use a counter like following in function where you're calling GPSCallback if(++count < 30) GPSCallback(msg); else{ count =0; std::ofstream output; output.open("file1.txt"); output.close(); GPSCallback(msg); }

Categories : C++

Making a program that sends an email which hyperlinks text in django
If you just want to make a classic link, you just have to use the HTML <a> tag. Also if you want to point to a particular URL, you can use the reverse() function (see the documentation about URL) Also set email.content_subtype = "html"

Categories : Python

How do I program a bluetooth module to broadcast a text string to an iOS device?
One way would be to create a custom GATT service with a characteristic containing your string. Then the iOS device could connect and read it. There is also the standard Device Information service which contains various string characteristics such as manufacturer name, serial no., device id etc. Maybe you could use that if it is suitable for your application. Your BGSript code among other things could set the value of the characteristic at run time if it is not constant. You can create the service using Bluegiga's Profile Development Kit. Documentation can be found here BLE112 Documentation and Software.

Categories : IOS

Displaying default text on variables that can be edited by the user on a C++ command-line program?
The traditional approach (going back to Fortran programs in the 1960s) was to do something like this, which works well on any type of console (even a print terminal): #include <iostream> #include <string> using namespace std; int main () { string nam = "StackUser"; cout << "Enter your name (or press <Enter> for '" << nam << "'): "; string newname; getline(cin,newname); if (newname.length() > 0) { nam = newname; } cout << "Username is " << nam << endl; return 0; } Having called this program default, it can now be run like this: $ ./default Enter your name (or press <Enter> for 'StackUser'): Username is StackUser $ ./default Enter your name (or press <Enter> for 'StackUser'): S

Categories : C++

How to program pcap with Objective-C and get HTTP request and response values in text format
MacAlyzer wasn't developed for your needs. I know because I'm the author. As already stated, Charles and Fiddler are web proxies and work entirely different (and serve different purposes). Diving a bit deeper into your question, communication between client and server happens IP-to-IP and not domain-to-domain. Domain information is not contained in the packets at the either the IP or TCP level. Instead computers request domain-to-IP lookup information which is then stored and communication is carried out using the client and server IP addresses. MacAlyzer, and really libpcap, don't have sophisticated packet dissection (like say Wireshark) and cannot display packet information as verbosely as other programs. Before I lost interest in the project I was planning a library that would allow m

Categories : Objective C

c++ program for reading csv writing into array; then manipulating and printing into text file (already written in matlab)
Change this line: array[row][col] = atoi( result.c_str ); to: array[row][col] = atoi( result.c_str() ); c_str() is a method, so you need parenthesis to call it. See http://en.cppreference.com/w/cpp/string/basic_string/c_str

Categories : C++

Program received signal SIGSEGV, Segmentation fault (program runs out of stack.)
The error is shown at this line: long a = thread_fake(); //in file1.c The likely way this could case a SIGSEGV is if your program has run out of stack. Examine actual crashing instruction in GDB with x/i $pc. If the instruction is a PUSH, or a CALL, then my guess is confirmed. Another possibility: you've compiled your code with optimization, and the actual faulting instruction has little to do with the source line it is attributed to. Update: Yes it gives a call call 0x804e580 <thread_fake>. What could be the solution? The solution is to not run out of stack. Execute a GDB where command, then, in each frame leading to the crash, execute info frame and look for frames that are excessively large. Don't allocate too much data on stack, or increase your stack size (u

Categories : C

Program received signal SIGSEGV, segmentation fault, Linked list program
You did not initialize numItems to zero. As unitialized it can be any number, including e.g. negative ones. Because of this your list is not created, hence pointer first points to NULL. Then the code segfaults in the function deleteList, when it tries to free memory at location NULL.

Categories : C

Java exceptions and program flow: how to know if the program will stop or continue after an exception is thrown?
It isn't executed because uncaught exceptions terminate the current thread(main thread in your case). test() throws a RuntimeException. Surrounding test() with a try-catch would catch the exception and allow your program to continue. try { test(); } catch(RuntimeException e) { System.out.println("test() failed"); }

Categories : Java

How are @interface, @implementation & program sections organised (in files) in an objective-c program?
The @inteface sections goes into a .h file. the @implementation goes into a .m file. This is probably explained in the book, although for convenience listings are usually given in one piece.

Categories : Objective C

Passing Data from a Java program to a Python program and getting results back
Sounds like a job for Jython! Jython is an embeddedable Python runtime written in Java. As long as you don't need to run your Python script in another process (e.g., want to be able to kill it, may use lots of memory, etc.), this is the best way by far.

Categories : Java

How to get data from read program to main program using execve and pipe?
Your "read.c" should print the result to the standard output. So, open the file and calculate the result as you are doing. Then use a printf() to print the result as this. This can be run from command line and the output should go to the terminal. printf("%f ", result); close (1); // Just in case, Making sure to flush for pipe Here is code that establishes the pipe between parent and child. I think this should help to resolve your project. Snip of process.c #include<stdio.h> #include<unistd.h> #include<stdlib.h> int main (int argc, char *argv[], char *envp[]) { int fd[2], pid; pipe (fd); pid = fork() if (pid == 0) { /* Child process */ close (1); // Close STDOUT. dup(fd[1]); // STDOUT will be fd[1] clo

Categories : C

visual basic .net program for xp platform program is being built on windows 7
I had something similar issue a few years ago, but in reverse. It might not be a .NET version issue though: it might be a 32 / 64 bit problem. After spending a lot of time on .NET framework requirements and re-re-reinstalling, once I compiled to 32 bit rather than Any CPU it would run on XP SP3 (even though it was 64 bit XP).

Categories : Vb.Net

power program from the book "c program. lang." version2, cycle
The initialisation in the for loop says p = 1, not n = 1. n is already provided as one of the function parameters, and serves as the counter. p is the accumulator for the result. A clearer way to write this might be: int p = 1; while (n--) { p *= base; } return p; The moral here is that function parameters are already local variables, and there's no need to create a duplicate local variable just for the sake of it. It's perfectly fine to modify function parameters.

Categories : C

Java UDP packets not reaching Server program from Client program
Sounds like network security configurations prevents you from receiving UDP packets. You need to configure your network such that it accepts UDP packets on the specified ports. Also, you have to configure your firewall to accept UDP packets on the specified ports as well.

Categories : Java

Hebrew data from RPG program to Java program incorrectly ordered
So I ended up finding out what was going on here and am answering my own question in case any one else ever runs into a similar issue. The Hebrew was being stored on the iSeries in code page 424. This is a Hebrew code page so all was well with the storing on the iSeries. We had some print drivers on the iSeries that were handling the Hebrew data correctly so I knew the issue had to be either on the transfer between the iSeries and Java or when we create the String of data in Java.It turns out that the iSeries was storing the Hebrew in print order so it was already in the order that I needed it to be to write it to the PDF. When we were transferring it to the Java program we were using an RPG character byte array. This character byte array will convert to Unicode when it is sent to th

Categories : Java

Need a program that continously listens to the Oracle DB and if any DML's are made it calls another program?
http://docs.oracle.com/cd/B14117_01/win.101/b10118/o4o00118.htm OracleDB has some events. Just try to use them; For example, when the db is updated - And to call another java program: Runtime.getRuntime().exec(/Here the argument/);

Categories : Java

C communication between C program and python program using exit code
No. The exit code of a process is a single integer, from 0 to 255. It cannot be an array, nor can it be outside that range. If you want to return data from a C program to its caller, print it on standard output (e.g, printf()). The exit status can only convey very basic information, like success/failure.

Categories : Python

(beginner c GUI program) GTK+ and C program is having problems with showing the icon
I have run this program with a png file at 48x48 pixels, the program works well. My operating system is Ubuntu 10.04 LTS. besides the png file is the same dir as program, or set the absolute directory

Categories : C

Parallel program no speed increase vs linear program
Since you are measuing time using clock on a Linux machine, I expect that the total CPU time is (roughly) the same whether you run one thread or multiple threads. Maybe you want to use time myprog instead? Or use gettimeofday to fetch the time (which will give you a time in seconds + nanoseconds [although the nanoseconds may not be "accurate" down to the last digit]. Edit: Next, don't use endl when writing to a file. It slows things down a lot, because the C++ runtime goes and flushes to the file, which is an operating system call. It is almost certainly somehow protected against multiple threads, so you have three threads doing write-data, a single line, synchronously, at a time. Most likely going to take nearly 3x as long as running a single thread. Also, don't write to the same fil

Categories : C++

Joda and moving the program/ having the program on multiple computers
Java is platform independent language so no matter if you write your code in one machine, it will surely be run as same with output in another machine. Regarding Joda Time: The Joda Time can give you time in seconds/hours/minutes.. http://joda-time.sourceforge.net/ Between calculation logic to calculate time in hours: hours = Hours.hoursBetween(new LocalDateTime(DateTime1), new LocalDateTime(DateTime2)).getHours(); You need to parse the current date for the date object to get it in DateTime format.

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.