fopen

Why does fopen(“any_path_name”,'r') not give NULL as return?

守給你的承諾、 提交于 2020-01-04 06:52:11
问题 While debugging some code I got something like below: #include<stdio.h> int main() { FILE *fb = fopen("/home/jeegar/","r"); if(NULL == fb) printf("it is null"); else printf("working"); } Here in fopen I gave a somewhat valid path name but not a filename. Shouldn't fopen return NULL then? But it does not return null! Edit: If I give path of valid directory in fopen then it will print working : If I give path of invalid directory in fopen then it will print it is null Edit: spec says Upon

fprintf debug assertion fail

你。 提交于 2020-01-03 17:22:39
问题 I have a program that runs correctly if I start it manually. However, if I try to add a registry key to start it automatically during startup, I get this error: Debug assertion failed (str!=null) fprintf.c line:55 I tried to add Sleep(20000) before anything happens, but I get the same error. Here's the code: main() { FILE* filetowrite; filetowrite = fopen("textfile.txt", "a+"); writefunction(filetowrite); } int writefunction(FILE* filetowrite) { fprintf(filetowrite, "%s", "\n\n"); ... } I

What happens if you exit a program without doing fclose()?

放肆的年华 提交于 2020-01-03 07:29:48
问题 Question: What happens if I exit program without closing files? Are there some bad things happening (e.g. some OS level file descriptor array is not freed up..?) And to the answer the same in both cases programmed exiting unexpected crash Code examples: With programmed exiting I mean something like this: int main(){ fopen("foo.txt","r"); exit(1); } With unexpected crash I mean something like this: int main(){ int * ptr=NULL; fopen("foo.txt","r"); ptr[0]=0; // causes segmentation fault to

使用Matlab读取二进制数据文件

淺唱寂寞╮ 提交于 2020-01-02 12:26:38
第一步:打开文件,用到的函数fopen fid=fopen('文件名',读取方式) fid:句柄值;小于0表示打开失败;大于0表示打开成功 文件名:字符串,使用单引号(本文例程'savedata.dat') 读写方式:(本文例程二进制文件只读方式打开rb) ‘r’:只读方式打开文件(默认的方式),该文件已存在。 ‘r+’:读写方式打开文件,打开后先读后写。该文件已存在。 ‘w’:打开后写入数据。该文件已存在则更新;不存在则创建。 ‘w+’:读写方式打开文件。先读后写。该文件已存在则更新;不存在则创建。 ‘a’:在打开的文件末端添加数据。文件不存在则创建。 ‘a+’:打开文件后,先读入数据再添加数据。文件不存在则创建。 注意:在打开方式后加’t’表示以文本方式打开;加‘b’表示以二进制数据方式打开;‘wb’‘wt’ fopen默认以二进制方式打开; 第二步:读取数据,用到的函数fread [data,count]=fread(fid,size,数据类型); fid:句柄值(与第一步句柄值同名对应); size:表示读取内容的大小;N(读取N个元素到一个列向量)、inf(读取整个文件)、[M,N](读数据到M×N的矩阵中,数据按列存放); 数据类型:int16、int32、double、float等等 data:读取的数据 count:读取数据的实际数量 第三步:关闭文件

How to escape url for fopen

不羁的心 提交于 2020-01-02 06:39:10
问题 It looks like fopen can't open files with spaces. For example: $url = 'http://gatewaypeople.com/images/articles/cntrbutnssttmnts12_main 616x200.jpg'; fopen($url, 'r'); returns false (mind the space in the url), but file is accessible by browsers. I've also tried to escape the url by urlencode and rawurlencode with no luck. How to properly escape the spaces? 回答1: You can use this code: $arr = parse_url ( 'http://gatewaypeople.com/images/articles/cntrbutnssttmnts12_main 616x200.jpg' ); $parts =

file doesn't open using PHP fopen

我怕爱的太早我们不能终老 提交于 2020-01-02 01:56:06
问题 i have tried this: <?php $fileip = fopen("test.txt","r"); ?> this should have opened the file in read only mood but it doesn't the test.txt file is in same folder as that of index.php (main project folder) the file doesn't open and when i put echo like : echo $fileip; it returned Resource id #3 回答1: The file did open just fine, you cannot echo it like that because it's a file pointer, not the contents of the file itself. You need to use fread() to read the actual contents, or better yet, use

PHP printing to local Thermal Printer, does not work without networkname

孤人 提交于 2020-01-01 05:45:08
问题 I've build a POS (Point of Sale) application in PHP that can print directly to a thermal printer. In most cases i run the application on a local webserver using WAMP. Part of the printing code is: $printer = "\\\\localhost\\TM-T88V"; // Open connection to the thermal printer $fp = fopen($printer, "w"); if (!$fp){ die('no connection'); } $data = " PRINT THIS "; // Cut Paper $data .= "\x00\x1Bi\x00"; if (!fwrite($fp,$data)){ die('writing failed'); } This code works fine as long as the PC is

file_get_contents (or curl, or fopen) problem with session data

孤人 提交于 2020-01-01 03:42:11
问题 i have a page that shows a value from session, lets call it www.domain-a.com/master.php and if i type it directly from the browser, it shows me the session value. but when i try to download it with file_get_contents (or other method) from another domain, like www.domain-b.com/slave.php, it is not retrieving the content protected by the session, just a blank page. i know it is because the server-b is trying to retrieve the content, not the user... anyone knows how to tell the domain-a that who

fwrite() more than 2 GiB? [duplicate]

巧了我就是萌 提交于 2020-01-01 03:21:10
问题 This question already has answers here : Is fopen() limited by the filesystem? (4 answers) Closed 6 years ago . I have a set of files that I want to concatenate (each represents a part from a multi-part download). Each splitted file is about 250MiB in size, and I have a variable number of them. My concatenation logic is straight-forward: if (is_resource($handle = fopen($output, 'xb')) === true) { foreach ($parts as $part) { if (is_resource($part = fopen($part, 'rb')) === true) { while (feof(

Using curl as an alternative to fopen file resource for fgetcsv

試著忘記壹切 提交于 2020-01-01 03:10:09
问题 Is it possible to make curl, access a url and the result as a file resource? like how fopen does it. My goals: Parse a CSV file Pass it to fgetcsv My obstruction: fopen is disabled My chunk of codes (in fopen) $url = "http://download.finance.yahoo.com/d/quotes.csv?s=USDEUR=X&f=sl1d1t1n&e=.csv"; $f = fopen($url, 'r'); print_r(fgetcsv($f)); Then, I am trying this on curl. $curl = curl_init(); curl_setopt($curl, CURLOPT_VERBOSE, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); curl