w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Reading and Writing data into a file printing invalid data
while(price != 0) only checked at the beginning of each loop. not each time price has changed. you can ommit the first read, and do: while (1) { fscanf(in,"%lf",&price); if (price == 0) // comparing floating point is bad, but I think it's ok here. break; fscanf(in,"%d",&disPercent); discountedAmount = price * disPercent / 100; finalPrice = price - discountedAmount; fprintf(out,"The original price is: %.2lf ",price); fprintf(out,"The discount amount is: %.2lf ",discountedAmount); fprintf(out,"Final Price is: %.2lf",finalPrice); }

Categories : C

Most efficent way of determing if a value is in a table
if($statment = mysqli_prepare($link, 'SELECT name FROM inventory WHERE name = ? LIMIT 1'))//name and inventory are arbitrarily chosen for this example { mysqli_stmt_bind_param($statement, 's', $_POST['check']); mysqli_stmt_execute($statement); mysqli_stmt_store_result($statement); } if(mysqli_stmt_num_rows($statement) == 0) //value not in table else //value in table I believe this would be sufficient. Note that I switched //value not in table and //value in table.

Categories : PHP

efficent way to sync sql-table with datatable
Create datadapter, set its commands, fill your datatable. Work with your datatable Then get datatable filled with changes DataTable updateDt = originalDt.GetChanges(); dataAdapter.Update(updateDt); This is the basic logic of working in disconnected mode and updating database.

Categories : C#

Core Data: Writing Batch of Records to Disk In Background
You can read through this link to learn a little bit more about saving core data records in the background. Essentially, your main context is a child of a background context that does the actual writing. This way, your main thread won't get blocked to write stuff to disk. It might, however, be temporarily blocked when merging/importing changes from a background context.

Categories : IOS

Reading Data and Writing into same excel file
In java you can achieve this by using third party libraries. One good library is POI by Apache. Please refer the below link for more information: Apache POI You can manipulate almost all types of office documents with the help of Apache POI API's.

Categories : Java

Reading fortran direct access data and writing formatted data - faster with python than with fortran?
Try using StreamIO see http://www.star.le.ac.uk/~cgp/streamIO.html That should allow random access without fixed record size and will probably result in using the same underlying O.S. system calls, thereby hopefully getting the same performance.

Categories : Python

Reading data from Excel sheets and building SQL statements, writing to output file in Python
try this.. # use 'a' if you want to append in your text file outFile = open(r'D:Scriptsupdate.txt', 'a') for i in myList: outFile.write(" UPDATE PERSON SET LegacyID = '%s' WHERE personid = '%s'" %( int(i[1]), str(i[0])))

Categories : Python

Windows Batch programming - Reading from a csv file and extracting certain data columns based on first column value
You need to enable delayed expansion: @echo off setlocal EnableDelayedExpansion set "_InputFile=..." for /f "tokens=1-18* delims=," %%A in (%_InputFile%) do ( Set _var1=%%A Set _var2=%%B ... if "!_var1!"=="RH" echo !_var2! )

Categories : Windows

writing text which reading and writing only one column
If this is a CSV file, which I can infer from the references to the csv file extension in the code, then you are much better off using a CSV parsing library such as opencsv, which will do all the hard work of parsing the file for you. You can then manipulate a CSV file object and save the result to the file.

Categories : Java

Warning writing table output as data.frame
DF <- read.table(text="C1 C2 C3 C4 1 -1 -1 1 1 1 -1 1 1 1 -1 1 1 -1 1 -1 ",header=TRUE) res <- table(stack(DF)) # ind # values C1 C2 C3 C4 # -1 0 2 3 1 # 1 4 2 1 3 res2 <- as.data.frame(res) # values ind Freq # 1 -1 C1 0 # 2 1 C1 4 # 3 -1 C2 2 # 4 1 C2 2 # 5 -1 C3 3 # 6 1 C3 1 # 7 -1 C4 1 # 8 1 C4 3 reshape(res2, timevar = "ind", idvar = "values", direction = "wide") # values Freq.C1 Freq.C2 Freq.C3 Freq.C4 # 1 -1 0 2 3 1 # 2 1 4 2 1 3 An alternative is res <- ftable(stack(DF)), which can be written to a file directly using write.ftable.

Categories : R

SQL Looping temp table and reading data
Please try below while loop: WHILE @PK <= @MaxPK BEGIN SELECT @Name = Name, @Marks = Marks from @MYTABLE print @Name print @Marks END Note: I guess, a where condition is required in select statement in order to print all data.

Categories : SQL

Reading data from text file and forming a table using php
Well here is what you can do.. Its my own creation function mydata($file_path,$start_line=0,$end_line=0) { $urldatafile = file($file_path) or die("Sorry, Couldn't load data!!"); if($end_line==0){ $linecount = count($urldatafile); $end_line = $linecount; } $array_data = array_slice($urldatafile, $start_line, $end_line); echo "<table>"; foreach ($array_data as $data) { $data = explode("===", $data); echo "<tr>"; echo "<td>{$data[0]}</td><td>{$data[1]}</td><td>{$data[2]}</td><td>{$data[3]}</td>"; echo "</tr>" } echo "</table>"; } In example.txt file write each new line with the following data values Data1===data2===data3===data4 Data1===data2===data3===data4 Data1===da

Categories : PHP

Reading data from text boxes inside a table
try changing: for (i = 0; i < rowLength; i++) { var value=[]; for (j = 0; j < 4; j++) { value.push(table.rows[i].cells[j].firstChild.data); } var val=JSON.stringify(value); var key = "xyz" + localStorage.length; localStorage.setItem(key, val); } to for (i = 0; i < rowLength; i++) { var value=[]; for (j = 0; j < 4; j++) { // getAttribute is probably what you're after here value.push(table.rows[i].cells[j].firstChild.getAttribute('value')); } var val=JSON.stringify(value); var key = "xyz" + localStorage.length; localStorage.setItem(key, val); }

Categories : Javascript

VB.net Visual Studio 2003 Reading Data from Excel Table
You may need to put additional quotes around the Extended Properties=Excel 5.0; part of your connection string (see connectionstrings.com for more information)

Categories : Database

Writing a variable with the value 0 into a file (Batch)
Problem with a digit directly before the redirector. try >filename echo 0 1>nul redirects standard output to nul (suppresses output) 2>nul redirects standard error to nul (suppresses error messages) 0 is standard input 3..9 similarly affected, nul can be a filename if desired.

Categories : Batch File

Reading data from a file with wrong count. What's best practice for reading in data?
Have you checked to make sure there aren't any extra spaces or newline's at the end of your text file? It may be possible that your last extra 'word' is due to trailing characters before the eof is reached.

Categories : C++

Gearman vs. Redis when writing PHP batch processors
Gearman is a distributed job server, Redis is a distributed store. So it is bit like comparing apples to oranges. Now, it is possible to implement Gearman-like features with Redis (based on the list data type for instance), but it is a do-it-yourself approach. While the principle is simple, the devil is in the details. The best Redis distributed queue implementations are for Ruby (Resque) and Python (Celery, RQ). There is a port of Resque for PHP: https://github.com/chrisboulton/php-resque There are important points to consider when comparing Gearman to a Redis-based implementation: Gearman jobs notify their completion to the client, and can be synchronous or asynchronous. If you do not implement something specific, a Redis queue will only support asynchronous jobs without completion

Categories : PHP

Reading and Writing to the same file in c++
If the records you are modifying are always the same size for both "new" and "old" data, it's no problem rewriting into the same file - it's only an issue if you are going to write data that is a different length than your "old" data. Just open the file with fstream f("somename.ext", ios::out|ios::in), and use f.seekg() and f.seekp() as required to go to the relevant place in the file (you can use tellp and tellg to figure out where you are currently)

Categories : C++

Reading file after writing it
Since you're writing over a network, most optimal solution would be to save your file in the local system first, then copy it to network location. This way you can avoid network connection problems. And as well have a backup in case of network failure. Based on your update, Try this instead: File.WriteAllText(outFileName, someString); header = null; using(StreamReader reader = new StreamReader(CsvFilePath)) { header = reader.ReadLine(); }

Categories : C#

fstream for reading and writing
You realize that ios_base::app is causing you to append to the end of the file no matter where you try to seek for write, right? Maybe you meant to specific ios_base::out instead? Also, for writes, it's seekp() not seekg().

Categories : C++

Reading and writing files in QML (Qt)
The example written by Nokia in the tutorial is not a pure QML program. It contains both C++ and QML. This kind of program is usually a C++ program which loads a QML file and renders it. C++ programs usually begin with a function called int main(int argc, char *argv[]);. In your case, it is this "main()" function which loads your QML main file (main.qml) file and renders it. But before loading the QML main file, you have to tell the QML system that you will use a custom QML class called FileIO. For this, you will have to use the int qmlRegisterType<T>(const char * package, int majorVersion, int minorVersion, char * classNameInQML); C++ function. It takes about 5 parameters : T : the C++ template parameter. It is your C++ class (FileIO). package : all QML classes are in package whi

Categories : Qt

reading and writing from file
Which locale is used when I perform the following command in bash? echo "Привет" > ./test.txt None. The data is written verbatim as it appears between the quotes. If the file is UTF-8, it will be written as UTF-8. Why when I change locale from "ru_RU.iso88595", "ru_RU.koi8r", etc. I always get correct result? cat somefile just dumps the file verbatim to your terminal. cat's and/or your shell's locale is not involved. The terminal shows it in whichever way it's been configured (and if you're using screen, it has its own input and output configuration separate from the shell and terminal). I get bash: warning: setlocale: LC_ALL: cannot change locale (ru_RU.iso88595) This is a message from Bash saying that it's having problems applying the new locale to the cu

Categories : Linux

Writing text to flat file using spring batch
You can simply write a class implementing FlatFileFooterCallback interface or just use default implementation SummaryFooterCallback class. http://static.springsource.org/spring-batch/apidocs/org/springframework/batch/item/file/FlatFileFooterCallback.html

Categories : Spring

I am writing a simple batch file to start programs
Try this: TASKLIST /FI "IMAGENAME eq processName.exe" /FI "status eq running" | find /I /N "processName.exe">NUL IF ("%ERRORLEVEL%"=="0" echo Process is running) ELSE (start "processName.exe")

Categories : Batch File

How to pass batch data to controller action from kendo UI grid in case of batch editing?
What you are doing wrong is that you did not say that it needs to be batch so you are actually sending the data to the server as soon as you finish editing the EmployeeName (exit edit mode) but your parameterMap function is incorrect when sending in non-batch mode because then there is no model in options (just directly the data). So, either add batch: true to the DataSoure definition (if you want to go in batch mode): var dataSource = new kendo.data.DataSource({ batch: true, schema: { model: { id: "EmployeeID", fields: { EmployeeID: { editable: false, nullable: true }, EmployeeName: { validation: { required: true } } } } }, ... or change parameter map to return options (only if you don

Categories : Jquery

QR Code reading/writing in Ruby
https://github.com/smparkes/zxing.rb YMMV, I'm the author. But I'm also the primary C++ maintainer of zxing and I use zxing.rb for a lot of testing so it should be as up-to-date as the C++ port is. No comment on the number of dependences: they're not a barrier for me, obviously.

Categories : Ruby

Postscipt: Reading a file, writing to pdf
The '==' operator specifically sends the output to stdout, it is not a 'marking operarator, that is it makes no marks on the output page. Ghostscript reads PostScript and interprets the program, any marking operations are fed as graphics primitives to the output device, and the device decides what to do with it. In the case of pdfwrite it writes a PDF marking operation, equivalent to the PostScript one, into the output file. Obviously, non-marking operators don't produce graphic primitives, and so they are not passed to the device. If you want to have your 'grabdate' routine write text on the page then you will have to select a font, (possibly re-encode it) scale it, set the current point then emit the text using a show operator. You will have to keep track of the current point and if i

Categories : Pdf

reading and writing file using autoresetevent in C#
When you use FileStream always use it with using like using (var fileStream = new FileStream(Filepath, FileMode.Open)) { Your code... } This ensures that the stream gets disposed properly. You can also use the StreamReader along with using using (var fileStream = new FileStream(Filepath, FileMode.Open)) { using (var reader = new StreamReader(stream)) { Your code... } }

Categories : C#

Writing and reading back from a .txt file
One option is to use literal_eval() when reading the matrix back: Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None. from ast import literal_eval mat = [[1, 2], [3, 4]] with open("file.txt", "w") as f: f.write(str(mat)) with open("file.txt", "r") as f: mat1 = literal_eval(f.read()) print mat1 # prints [[1, 2], [3, 4]] print type(mat1) # prints <type 'list'> Another option is to use pickle: import pickle mat = [[1, 2], [3, 4]] with open("file.txt", "w") as f: pickle.dump(mat, f) with open("file.txt", "r") as f: mat1 = pickle.load(f) print mat1 # prints [[1, 2], [3, 4]] p

Categories : Python

Reading and writing to the same file using the same fstream
You are falling foul of a restriction upon the intermixing of read and write operations on a file opened in update mode that MS's fstream library inherits from from the its C <stdio.h> implementation. The C Standard (I cite C99, but it doesn't differ in this point from C89) at 7.19.5.3/6 states: When a file is opened with update mode ('+' as the second or third character in the above list of mode argument values), both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, fsetpos, or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the inpu

Categories : C++

.NET 4.0 Reading and writing from and to and MDB file (2010)
I'm not sure MS has create a Linq provider for either ODBC or OLE. You might have to do it yourself, without anything fancy I'm afraid. You could use Microsoft.Jet.OLEDB.4.0 as your provider. It's a long time since I've had to do this but, try something like (this is just stab here and I haven't tested this even compiles, but it shouldn't be too far off): var connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data.mdb"; var query = "select * from Regions"; using (var connection = new OleDbConnection(connectionString)) using (var command = new OleDbCommand(query)) { command.Connection = connection; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { // Not 100% sure here.. var regionName = (string)reader

Categories : Dotnet

Reading and writing to arduino at the same time
The key to do several things "at the same time" is to understand that the Arduino has only one core. Thus it will process stuff only one step after the other. Now suppose you want to perform three functions "action1()", "action2()" and "action3()" at "the same time. In order to achieve this you must ensure that all actions can be performed as fast as possible, preferably sub milliseconds none of them "blocks" Then the desired effect is achieved by just putting them into succession like so void loop() { action1(); action2(); action3(); } This is the basic idea of "cooperative multitasking". It follows that none of the actions must utilize delay() or blocking waits. For example while(Serial.available() == 0); is a blocking wait and must be avoided. Things get more com

Categories : C#

Reading/Writing Binary files
If you only write ASCII characters to a file, it will be possible to open it in Notepad or any other text editor just fine: local out = io.open("file.bin", "wb") local str = string.char(72,101,108,108,111,10) -- "Hello " out:write(str) out:close() The resulting file will contain: Hello On the other hand if you write real binary data (for instance random bytes) you will get garbage: local out = io.open("file.bin", "wb") local t = {} for i=1,1000 do t[i] = math.random(0,255) end local str = string.char(unpack(t)) out:write(str) out:close() This is similar to those video game save files you have seen. If you still don't get it, try to write all possible octets to a file: local out = io.open("file.bin", "wb") local t = {} for i=0,255 do t[i+1] = i end local str = string.char(unpack(

Categories : Lua

Reading bytestream and writing to file
File f = new File(//PATHFILE); FileOutputStream fOut = new FileOutputStream(f); InputStream is=//InputStream byte data[] = new byte[1024]; int count; while ((count = is.read(data)) != -1) { fOut.write(data, 0, count); } fOut.flush(); fOut.close(); is.close(); That's my code and works perfectly

Categories : Java

Reading/Writing with System Calls
char xyz[3] = "XYZ"; trywrite = write(XYZ, &xyz, 120); This is your main problem. You are trying to write 120, when you only have 3. You have other problems: you are not checking what read and write return read and write don't return int, but ssize_t open(path, 0) works, but you should use O_RDONLY you are using void main instead of the correct int main as Jonathan Leffler pointed out, you should use buffer instead of &buffer

Categories : C

writing and reading using socket in unity 3d
I think you have taken this code from http://answers.unity3d.com/questions/15422/unity-project-and-3rd-party-apps.html, but I think there is an error in this code. I'll repeat here what I posted there. The following code does not work correctly: public String readSocket() { if (!socketReady) return ""; if (theStream.DataAvailable) return theReader.ReadLine(); return ""; } This caused me a headache for quite few hours. I think that checking DataAvailable on the stream is not a reliable way to check if there is data to be read on the streamreader. So you do not want to check for DataAvailable. However, if you just remove that, then the code will block on ReadLine when there is no more to read. So instead, you need to set a timeout for reading from the stream, so that y

Categories : C#

Reading and writing to files isn't working in C++
When you need to debug something like this - saying "all the functions are being run and all the variables are being created, and it compiled without any warnings" isn't really debugging. Debugging - this doesn't work. Remove bits until you find what doesn't work. Like you said - all variables are what you expect them. So... try and see if, for example, the way you read and write from a file works. Just write a small program that opens a file like you open it, reads from it like you do and then writes... whatever back into it in the same way you do. See if that works. In other words, try and find the smallest program that reproduces what you see.

Categories : C++

How to implement Spring batch remoting and still maintain order of writing?
I think you can't do that because Table are naturally unsorted. If you need them to be ordered in some way add a order column managed by writer. First partition write 1-100, second partition 101-200 and so on. Next step reader will get items order by [order column]. Holes between order column due to missing write in previous partitioners are not an issue. My 2 cents

Categories : Java

Reading/writing files to/from a struct/class
Well... this can be ok, occasionally. But it is dangerous if you don't know what you're doing, or someone comes in and wants to modify something. It'd probably be best to read / write your individual member variables one at a time. file.read( &m_fMyFloat, sizeof( float ) ); file.read( &m_nMyIntA, sizeof( int ) ); file.read( &m_nMyIntB, sizeof( int ) ); etc, etc... Padding can be included, yes... but it's really uncommon to have padding between the variables themselves. The more common issue is that if your class derives from another, you'll be read/writing over the virtual table of that class. This is a really bad and somewhat sneaky problem!! It's the same reason you should avoid using any ZeroMemory methods on a this pointer. So basically, just use a standard patter

Categories : C++

reading and writing in the padding bits of a structure
I am not an expert in padding but I don't believe it is possible to guarantee any padding, at least not without special and possibly implementation-specific options. It is not defined behavior to use reinterpret_cast for anything other than to convert back to the original pointer. reinterpret_cast means you are doing something dodgy in your code. This question talks about what padding is initialized to Is zero initialization of structures guaranteed to wipe padded areas?

Categories : C++



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