.txt Saving and naming the file [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Thats the deal, I am trying to make and offline Email Manager, where you can write and store emails in different folders.
Written in .txt files that contain the basic information of an email (to:, from:, body :, etc). I am having issues on the following process.
-Each email has an ID that helps on searching and administration. I want to give the name of .txt files the ID related to the email that contains. So .... How can I create a .txt file that has the name of the ID and the ID is given by the user.
Thank you.

You have to create a buffer to build your filename.
#define BUFFERSIZE 256 /* max size of a path */
FILE * fp ;
char buffer[BUFFERSIZE] ;
snprintf(buffer, BUFFERSIZE, "/path/to/file/%s.txt", your_id_string);
fp = fopen(buffer, "w+") ;

Related

How to create file in c with ansi encoding [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
How can I create file in C (not C++ or C#) with ANSI encoding?
When I create txt file by this code:
FILE* file_ptr;
file_ptr = fopen("new filler.txt", "r");
It creates file with UTF-8 encoding. How can I fix that automatically?
If you open the file in binary mode, there is no encoding at all and you are free to control every byte that goes into the file.
FILE * const f = fopen("myansi.txt", "wb");
fputs("\033+", f);
fclose(f);
The above puts the ANSI.SYS sequence for clearing the screen into the file.

Learning the syntax of files in C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I can't understand the syntax of writing in files in C.
I was requested in class to open a file named Numbers.txt and then print from 1 to 10 and each new line. I dont understand the syntax of it.
We use fopen,fwrite,fclose.
need help with understanding how to work with it.
You use a FILE to assign a file to something you can use. fopen opens a file depending on if the file exists or not.
FILE *pFile = fopen("Filename.foo","r");
This opens the file that is located in your project with the same filename. The 2nd parameter is the mode of the file — how you want to use it. Here is a table of modes. You must always check the return value to ensure it is not NULL, indicating that the program was unable to open the file as requested.
You always want to close the file when you're done editing it by using fclose.
fclose(pFile);
fwrite is one way of writing to a file; fprintf and family are another. Basically think about it like you opened a text editor and typed something in the file. You need to create a buffer (a place to store the numbers), then write the numbers into the file. Here is the reference for fwrite. I can't do all of your homework.

Linux script in C get file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have own script in C for linux, it is working with string loaded from file. I compiled on server gcc -pthread -o pipeline pipeline.c. It is working. Now I am running this script any like this ./pipeline UPPERCASE LOWERCASE < my_file.txt. I can read all arguments but I dont know how to read file name behind < in this script. It is possible, or how is it working?
The contents of that file will show up on your process's standard input (stdin). You don't get the name of the file, as the same interface will be used in situations where there's no filename, such as when the output of another process is piped to yours (doSomething | pipeline UPPERCASE LOWERCASE), or when the user's terminal is used for input by default.

What file extensions can be opened with c [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
what types of file extensions can be opened with c
I know we can use .dat and .txt but what more can be used?
What types can be modified?
can I actually edit HTML, C++.
I'd like to open system 32.
An extension simply a convenient and conventional embellishment to a file name.
Any file can be opened with c (subject to permissioning).
You might want to choose between "text" and "binary" formats accordingly. But we're into specifics at this point, and such choices are down to you.
You can open any file extension in C. Only if you have permissions. Also, Bathsbeba answer is correct, just check out this link to see what are the main types of extensions.
To open a file with any extension, do this:
fopen ("file.extension", "your mode");
You can open it in binary and text formats. If you do not know how to open in binary, this is an example:
fopen ("file.extension", "wb");
To open in write binary mode.

Read from pipe large files C/Bash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am working on a web server in C. But for http request parsing and response I am using bash.
Communication between bash and server is going through fifo pipes.
I need to find a requested file like /index.html and send it through the pipe to server and then send it to client.
My code's looking like this:
bash:
cat $filename>/tmp/pipeToServer filename is something like index.html or image.jpg
And at server side I am reading it like:
pipe_r = open(/tmp/pipeToServer, O_RDONLY);
n = read(pipe_r, buffer2, sizeof(buffer2));
and buffer2 is char buffer[4096]
So my problem is that this is working only with small files like 1kb, but when the file is larger, I can't read the whole content at pipe because of a limit on the buffer size.
Increase the size of your buffer2 so that all the contents of the file are read. As of now maybe your buffer size is less than the contents of your file,so all values are not being read.

Resources