file-handling

Php create a file if not exists

感情迁移 提交于 2019-12-18 04:01:27
问题 I try to create files and write the contents dynamically. Below is my code. $sites = realpath(dirname(__FILE__)).'/'; $newfile = $sites.$filnme_epub.".js"; if (file_exists($newfile)) { $fh = fopen($newfile, 'a'); fwrite($fh, 'd'); } else { echo "sfaf"; $fh = fopen($newfile, 'wb'); fwrite($fh, 'd'); } fclose($fh); chmod($newfile, 0777); // echo (is_writable($filnme_epub.".js")) ? 'writable' : 'not writable'; echo (is_readable($filnme_epub.".js")) ? 'readable' : 'not readable'; die; However, it

modify existing contents of file in c

二次信任 提交于 2019-12-17 18:59:29
问题 int main() { FILE *ft; char ch; ft=fopen("abc.txt","r+"); if(ft==NULL) { printf("can not open target file\n"); exit(1); } while(1) { ch=fgetc(ft); if(ch==EOF) { printf("done"); break; } if(ch=='i') { fputc('a',ft); } } fclose(ft); return 0; } As one can see that I want to edit abc.txt in such a way that i is replaced by a in it. The program works fine but when I open abc.txt externally, it seemed to be unedited. Any possible reason for that? Why in this case the character after i is not

Why am i getting this warning in “if (fd=fopen(fileName,”r“) == NULL)”?

大憨熊 提交于 2019-12-17 14:01:10
问题 FILE *fd; if (fd=fopen(fileName,"r") == NULL) { printf("File failed to open"); exit(1); } This is a code snippet. When I compile it with gcc, i get the following warning:- warning: assignment makes pointer from integer without a cast When I put fd=fopen(argv[2],"r") within brackets, the problem gets solved.. I am not able to understand where am i converting integer to pointer when the brackets are not put. 回答1: Due to operator precedence rules the condition is interpreted as fd=(fopen

Compile a C/C++ Program and store standard output in a File via Python

与世无争的帅哥 提交于 2019-12-14 03:36:21
问题 Let's say I have a C/C++ file named userfile.c . Using Python, how can I invoke the local gcc compiler so that the file is compiled and an executable is made? More specifically, I would like to provide some input (stdin) via some file input.txt and I want to save the standard output into another file called output.txt . I saw some documentation that I will need to use subprocess, but I'm not sure how to call that and how to provide custom input. 回答1: A simple solution will be as given below:

How Can I read a file at preprocessing time

馋奶兔 提交于 2019-12-14 03:33:24
问题 I need to compile my code based on version number of the project i am working on. In short, i will read the version number from a file and enable or disable certain part of my code/. How can i read the version number from a file at compile time in c/c++?. I am trying to do something like this static const unsigned int version = #include "version" ; I am getting compiler error. 回答1: file.c #include <stdio.h> static const float version = #include "file.h" ; int main() { printf("Version is : %f

Trouble implementing a (stable) method of retrieving n bytes from file

梦想的初衷 提交于 2019-12-13 17:52:45
问题 One of the purposes of the library of which I am developing is to retrieve a specified amount of bytes from a file, in this specific case I am wishing for access to /dev/random to retrieve entropy based random sequences. My main issue with fread is that it will hang indefinitely when waiting for more entropy, and this is unwanted. My next choice would have been wrapping fread with feof to take bytes in chunks, then I could at least provide percentages complete for a better experience,

java.io.FileNotFoundException The system cannot find the path specified [closed]

寵の児 提交于 2019-12-13 10:07:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have a timer set to invoke a class that contains pdf generating codes.I have set the file path where it needs to be saved..but it is showing exception as java.io.FileNotFoundException : D:\ (The system cannot find the path specified) .I dont know where is the mistake.. Here is my code.. try { OutputStream file

How can I manage and a csv file in c?

蹲街弑〆低调 提交于 2019-12-13 09:45:44
问题 i have a csv file and which look like this : 1;53453;45847865 1;37567;53687686 . . . . n. 1;999768;5645644 and i want to open the file , read it and then split each line to 3 tokens which will be seperated from the semicolon .... e.g 1;35435;75675 token1 = 1; token2 = 35435; token3 = 75675; the code that i have is a main which i open and read the file and a function which i take manually a string of characters and split it ... I want to know if there is an easier way to implement this and a

How to check a file exist or not in unity android?

橙三吉。 提交于 2019-12-13 09:41:28
问题 I want to find the file in the path known and if it is pre-existing in android then trigger an event(enable/disable canvas) with it. Here is an example I used - public void FileChk(){ string filePath = "file://" + Application.temporaryCachePath + "/" + "folder23" + "/" + fileName; if (!fileName.Exists) { //event } else { //event } } what am I doing wrong here and how do I get this event to trigger when the file exists. 回答1: You can use the System.IO namespace. public void FileChk() { string

Text File Handling in Visual Basic

对着背影说爱祢 提交于 2019-12-13 09:22:39
问题 I have a text file contains delimited records. 1243;jhhf';982u4k;9u2349;huf8 kij;9238u;98ur23;jfwf;03i24 I need to replace the value of 4th part from every record with the value returned from database or someother source. Any clue ? expecting VB CODE 回答1: Take a look at here( for C# language ); Split string in C# 回答2: You could try this (written in C#): C# release List<string> newLines = new List<string>(); string[] lines = File.ReadAllLines(filename); foreach (string line in lines) { string[