file-handling

While writing into a file , Where intermediate data stored in between fopen() and fclose()?

血红的双手。 提交于 2019-12-11 08:55:17
问题 Below is a small program which takes information from user and write it into a file teacher.txt . I am using only one array q2[30] for taking input and writing into a file using fprintf() . But when i want to enter more teacher then again loop will execute but at this time fclose() will not appear so data will not be write/save(don't know) into file also previous value of q2 get erased/overwrite with new input. So in this case where data is stored/write by fprintf() .Because when i manually

Python deleting a block of lines from a file

家住魔仙堡 提交于 2019-12-11 06:14:23
问题 I'm struggling to figure out as to how I should go about deleting a block of lines from a file. Below is the code #!/usr/bin/python import argparse import re import string ##getting user inputs p = argparse.ArgumentParser() p.add_argument("input", help="input the data in format ip:port:name", nargs='*') args = p.parse_args() kkk_list = args.input def printInFormat(ip, port, name): formattedText = '''HOST Address:{ip}:PORT:{port} mode tcp bind {ip}:{port} name {name}'''.format(ip=ip, port=port

Move a file, AX2012

你。 提交于 2019-12-11 04:34:12
问题 I'm trying to move a file, nothing clever. The problem I am having is explained in the AX WONDERS blog. The reason for this is that when using an AX class that runs on the server, the exception never comes back to the client and therefore cannot be handled correctly.... the operation will not fall into the Exception::CRLError exception If the source file is opened by MSWord, for example, an exception is thrown in the fileLocked method, which is both infuriating yet amusing. Any suggestions

How to write data to a file in Hindi language?

点点圈 提交于 2019-12-11 04:29:03
问题 I am trying to write data to a file in a non-roman script using python tkinter. I want to write data to a file in Hindi language which follows the Devanagari Script. While, it is working perfectly alright when I write some data in English, while writing to the file in Hindi language is throwing some errors. How do I resolve this issue? I tried adding (encoding='utf-8') in filedialog command. Doing this, it gives the following error: _tkinter.TclError: bad option "-encoding": must be

edit file contents in perl

情到浓时终转凉″ 提交于 2019-12-11 04:25:35
问题 I would like to read an input file and then delete a line if it matches my regex. and have the file saved without that line. I have written open(my $fh, '<:encoding(UTF-8)', $original_file_path or die "Could not open file $original_file_path $!"; while (my $line = <$fh> ) { chomp $line; if ($line ~=/myregex/){ delete line from file } } Thank you 回答1: You can modify a file in place by using -i flag. In your case, a simple one liner would do: perl -i -ne 'print unless /myregex/' the_name_of

How can I delete from a text file? [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 02:33:19
问题 This question already has answers here : File Handling in C - Removing specific words from a list in text file (2 answers) Closed 2 years ago . Hi guys I have a text file which is known as dictionary.txt. Basically i am doing a menu of two choices, 1. add new words to dictionary and 2. delete words from dictionary. right now i managed to do the menu and add new words. However, I am stuck at deleting from a file. I want that when the user enters for example "runners" the word is searched in

Simple Delete File Program in ANSI C for Windows

和自甴很熟 提交于 2019-12-10 22:05:43
问题 Looking for a simple program to a delete a file written in ANSI C. Just as an example how would you delete a file at "C:\test.txt" with C? 回答1: You can delete a file from the OS using the remove() function. Like so: #include <stdio.h> int main(){ if(remove("HELLO.txt") == -1) perror("Error in deleting a file"); return 0; } The remove() function is defined in stdio.h . Here are some docs. 回答2: Use the remove function. I believe it is in "stdio.h" 回答3: remove or unlink remove is declared in

Perl: Please explain to me the following behaviours of while()

一个人想着一个人 提交于 2019-12-10 18:11:11
问题 1.Why does while (<$filehandle>) iterate through a file seemlessly, but it doesn't iterate through lists or arrays without manipulating the array itself (like using while ($_ = shift @array){print $_} ? How does this happen? 2.How is it that while ($var = @array){print $var} manages to iterate through the whole array? Shouldn't $var just get the number of indices in @array and return that value (so creating an infinite loop)? From my understanding while() reads the conditionality of a

Cannot write the data in the file, no error in the program C++

社会主义新天地 提交于 2019-12-10 15:55:29
问题 I cannot write data on a file with these pointer variables in the class. there is no error in the program but no data is written on the file. kindly someone tell me that where i am doing something wrong. #include <iostream.h> #include <fstream.h> class studentinfo { private:/*Creating Private Data Members */ char* VUID; char* campusID; char* Studentname; char* Fathername; public: void Storefile();/* Function to Store Data in the File*/ char Display();/*Function to Read and then Display Data

Create a file descriptor

坚强是说给别人听的谎言 提交于 2019-12-10 11:44:48
问题 I want to create a file descriptor in C whose value i will specify in code. I have a integer variable which specifies the value of file descriptor to be created. For example i may need a file descriptor whose value is 5 and later associate that with the file named "sample.dat" . 回答1: You need dup2() http://linux.die.net/man/2/dup 回答2: fd = open ("sample.dat", O_RDONLY); open the file dup2 (fd, 5); and copy the file descriptor fd into the descriptor number 5 now you can do read (5, buffer,