fopen

文件与流 -- fopen/fclose

折月煮酒 提交于 2019-12-17 17:57:00
#include <stdio.h> int main(void) { FILE* fp = NULL; fp = fopen("abc.txt","a+"); //fopen(path, mode) 以“mode”的方式打来文件abc.txt if (NULL == fp) { printf("fopen fail\r\n"); perror(""); } else { fwrite("hello filestream!", 1, 17, fp); //fwrite(const char* string, size_t size, size_t nmem, fp)将string指向的字符串写到fp指向的文件中,单个写入内容大小为size,总共nmem个size大写的内容写入 fclose(fp); } return 0; } 来源: 51CTO 作者: tresordie 链接: https://blog.51cto.com/4265810/2068688

Read input.txt file and also output.bmp file from terminal (C-programming)

老子叫甜甜 提交于 2019-12-17 17:16:02
问题 I have to do an assignment where I have to write a C-Programm, where it gets the input-file-name from the console as command line parameter. It should move the data from the input.txt file (the input file has the information for the bmp file - color etc.) to the generated output.png file. The 20 20 parameters stand for width and height for the output.png image. So the console-request for example (tested on Linux) will look like this: ./main input.txt output.bmp 20 20 I know that this code

C - Working with fopen, fclose, fputc etc

女生的网名这么多〃 提交于 2019-12-17 17:15:24
问题 I've got this code finally working with a single argument on my command line, i.e. one file for it to work with, although I designed the code with the concept of it working with an unlimited number of files. What it does is take some X number of text files containing words separated by spaces, and replaces spaces with \n thus creating a list of words. Though, it successfully completes the first argument, it just ignores the 2nd. Another minor problem seems that it also prints out some garbage

Remove Line From CSV File

北城余情 提交于 2019-12-17 14:52:19
问题 I have .csv file with 4 columns. What's the easiest way to remove a line identical with the id of the first column? Here's where I got stuck: if($_GET['id']) { $id = $_GET['id']; $file_handle = fopen("testimonials.csv", "rw"); while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); if ($id == $line_of_text[0]) { // remove row } } fclose($file_handle); } Unfortunately, databases were not a choice. 回答1: $id = $_GET['id']; if($id) { $file_handle = fopen("testimonials.csv", "w

fclose() causing segmentation fault

折月煮酒 提交于 2019-12-17 14:31:09
问题 I have a tab-delimited text file that I am parsing. Its first column contains strings of the format chrX , where X denotes a set of strings, e.g., "1", "2", ..., "X", "Y". These are each stored in a char* called chromosome , as the file is parsed. The text file is sorted on the first column lexicographically, i.e., I will have a number of rows starting with "chr1", and then "chr2", etc. At each "chrX" entry, I need to open another file that is associated with this entry: FILE *merbaseIn; //

fclose() causing segmentation fault

北城以北 提交于 2019-12-17 14:30:52
问题 I have a tab-delimited text file that I am parsing. Its first column contains strings of the format chrX , where X denotes a set of strings, e.g., "1", "2", ..., "X", "Y". These are each stored in a char* called chromosome , as the file is parsed. The text file is sorted on the first column lexicographically, i.e., I will have a number of rows starting with "chr1", and then "chr2", etc. At each "chrX" entry, I need to open another file that is associated with this entry: FILE *merbaseIn; //

Open file with fopen, given absolute path on Windows

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 11:02:42
问题 I'm trying to make a program that counts the number of lines of a file, when I try to pass the absolute path to the fopen function, is simply tells me that is not found, here is my code: #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { int i=0; char array[100]; char caracteres[100]; FILE *archivo; archivo = fopen("C:\Documents and Settings\juegos psps.txt","r"); if (archivo == NULL){cout<<"Dont Work";} while (feof(archivo) == 0

Open file with fopen, given absolute path on Windows

北慕城南 提交于 2019-12-17 11:02:41
问题 I'm trying to make a program that counts the number of lines of a file, when I try to pass the absolute path to the fopen function, is simply tells me that is not found, here is my code: #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { int i=0; char array[100]; char caracteres[100]; FILE *archivo; archivo = fopen("C:\Documents and Settings\juegos psps.txt","r"); if (archivo == NULL){cout<<"Dont Work";} while (feof(archivo) == 0

Overwrite Line in File with PHP

一曲冷凌霜 提交于 2019-12-17 07:41:13
问题 What is the best way to overwrite a specific line in a file? I basically want to search a file for the string '@parsethis' and overwrite the rest of that line with something else. 回答1: If the file isn't too big, the best way would probably be to read the file into an array of lines with file(), search through the array of lines for your string and edit that line, then implode() the array back together and fwrite() it back to the file. 回答2: If the file is really big (log files or something

What happens if I don't call fclose() in a C program?

孤人 提交于 2019-12-17 03:32:31
问题 Firstly, I'm aware that opening a file with fopen() and not closing it is horribly irresponsible, and bad form. This is just sheer curiosity, so please humour me :) I know that if a C program opens a bunch of files and never closes any of them, eventually fopen() will start failing. Are there any other side effects that could cause problems outside the code itself? For instance, if I have a program that opens one file, and then exits without closing it, could that cause a problem for the