file

ANSI C - Text File: Modify Line?

♀尐吖头ヾ 提交于 2021-02-17 06:50:10
问题 I have this text file: Line 1. "house" Line 2. "dog" Line 3. "mouse" Line 4. "car" ... I want to change Line 2. "dog" in new Line 2."cards" how can I do? thanks! (sorry for my bad English) 回答1: Your program could like this: #include <stdio.h> #include <stdlib.h> #define MAX_LINE_LENGTH 1000 int main() { FILE * fp_src, *fp_dest; char line[MAX_LINE_LENGTH]; fp_src = fopen("PATH_TO_FILE\\test.txt", "r"); // This is the file to change if (fp_src == NULL) exit(EXIT_FAILURE); fp_dest = fopen("PATH

how can i read from a binary file?

99封情书 提交于 2021-02-17 06:09:38
问题 I want to read a binary file that its size is 5.5 megabyte (a mp3 file). I tried it with fileinputstream but it took many attempts. If possible, I want to read file with a minimal waste of time. 回答1: Try this: public static void main(String[] args) throws IOException { InputStream i = new FileInputStream("a.mp3"); byte[] contents = new byte[i.available()]; i.read(contents); i.close(); } A more reliable version based on helpful comment from @Paul Cager & Liv related to available 's and read 's

Can not read text file in C

荒凉一梦 提交于 2021-02-17 05:36:33
问题 I have an assignment to create a menu program that uses a linked list to store a list of phone catalog. Here is my source code: int isempty(FILE *in) { return in == NULL; } node *makenewnode(item newitem) { node *newnode = (node *) malloc(sizeof(node)); newnode->info = newitem; return newnode; } int countlines(FILE *datain) { int lines = 0; char string[MAX]; while (fgets(string, MAX, datain)) lines++; return lines; } node *push(node *listin, item newitem) { node *newnode = makenewnode(newitem

Can not read text file in C

守給你的承諾、 提交于 2021-02-17 05:36:05
问题 I have an assignment to create a menu program that uses a linked list to store a list of phone catalog. Here is my source code: int isempty(FILE *in) { return in == NULL; } node *makenewnode(item newitem) { node *newnode = (node *) malloc(sizeof(node)); newnode->info = newitem; return newnode; } int countlines(FILE *datain) { int lines = 0; char string[MAX]; while (fgets(string, MAX, datain)) lines++; return lines; } node *push(node *listin, item newitem) { node *newnode = makenewnode(newitem

FileStream.Write not Writing to File

孤街醉人 提交于 2021-02-16 21:33:47
问题 I'm passing some Base64 encoded strings through WCF, and I'm attempting to write them to a file. However, despite the fact that my FileStream object has a Length greater than 0, my file on disk remains empty. FileStream fs = new FileStream(Config.Instance.SharedSettings.SaveDir + StudyInstance.StudyId + "\\tmp.ext", FileMode.Create); EncodeBlock eb = new EncodeBlock(); while (eb.Part != eb.OfParts || eb.OfParts == 0) { eb.ToDecode = ps.StudyService.GetInstancePart(StudyInstance, s, eb.Part+ 1

How do I make my own header file in C?

你离开我真会死。 提交于 2021-02-16 19:36:14
问题 I tried to make my own header file but it doesn't work vim says wget.h:2:2: error: invalid preprocessing directive #ifndef__WGET_H__ wget.h:3:2: error: invalid preprocessing directive #define__WGET_H__ wget.h:7:2: error: #endif without #if My code is this: //wget header file #ifndef__WGET_H__ #define__WGET_H__ int my_wget (char web_address[]); #endif /*__WGET_H__*/ it seems fine to me (the examples I have read are much alike with mine) and I don't know what went wrong. Any ideas? 回答1:

C++ : Read random line from text file

限于喜欢 提交于 2021-02-16 18:58:49
问题 I am trying to code a program that picks 3 random lines from a text file (that contains 50 lines) and outputs them to the screen. Here is my current code: string line; int random = 0; int numOfLines = 0; ifstream File("file.txt"); srand(time(0)); random = rand() % 50; while(getline(File, line)) { ++numOfLines; if(numOfLines == random) { cout << line; } } I can get it to print one random line like it does above but not three random lines. 回答1: What you should do depends on what exactly you

C++ : Read random line from text file

时光毁灭记忆、已成空白 提交于 2021-02-16 18:58:34
问题 I am trying to code a program that picks 3 random lines from a text file (that contains 50 lines) and outputs them to the screen. Here is my current code: string line; int random = 0; int numOfLines = 0; ifstream File("file.txt"); srand(time(0)); random = rand() % 50; while(getline(File, line)) { ++numOfLines; if(numOfLines == random) { cout << line; } } I can get it to print one random line like it does above but not three random lines. 回答1: What you should do depends on what exactly you

How can I import a .pyc compiled python file and use it

我的未来我决定 提交于 2021-02-16 14:50:22
问题 Im trying to figure out how to include a .pyc file in a python script. For example my script is called: myscript.py and the script I would like to include is called: included_script.pyc So, do I just use: import included_script And will that automatically execute the included_script.pyc ? Or is there something further I need to do, to get my included_script.pyc to run inside the myscript.py ? Do I need to pass the variables used in included_script.pyc also? If so, how might this be achieved?

Javascript, Typescript, Angular 5 - Open and read file

你说的曾经没有我的故事 提交于 2021-02-16 14:49:49
问题 I am working with Angular 5, I have an application in which I need to read an AMP HTML file as text. This file is contained in a component and should only be accessed from this component. I would like to be able to open the file in read-only by giving its name. I'm actually searching for something like this: let file = open('amp.html'); Is it possible? If not how can I do to achieve this? 回答1: If you're writing browserside JS You can't just simply read a file. The JS is running on your