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.
Related
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 11 months ago.
Improve this question
I have a C program which reads its input from the command line, I would like to feed the executable with the output of ls | wc -m command, as I need to call two instances of the executable (./a.out1 , ./a.out2) using that same input and make them running in parallel (pipes ?).
Thank you for your help in advance!
You say you want to use a pipe, so first of all you need to adapt your program to read the input from stdin instead of argc and argv. Input passed via a pipe is not added to the command line argument list.
To pipe stdout of a process to multiple other processes, you can use tee and process substitutions:
ls | wc -m | tee >(./a.out1) >(./a.out2) >/dev/null
However, the reason why you require it be piped (as opposed to passed as an argument) isn't clear to me, so storing the output in a variable as suggested in the comments would work just as well for the example you present.
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.
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.
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 8 years ago.
Improve this question
In a programming competition , they mentioned this:
" How to answer to the problems?
In the problems you are up to solve, you have to read data from a file .IN, and write the results in a file OUT. "
I am used to the regular way of programming, writing the code in IDE , compiling , then executing it to see what's going on, and it worked, however my answers were refused.
Does anyone know anything about those file.IN and .OUT thing?
I mean, how can I get my program to take input from a textfile in which I write the dat aI want to give to the program, and make it send the the output to another textfile ?
Thanks
Include stdio.h in your header files.
In your main function, include the following lines on top.
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
In most online programming competitions, input is given through stdin and output through stdout. However, in this case, you have to read input from a file (.in) and write to a file (.out). freopen takes the stream(stdin, stdout) specified as the third argument to re-open the stream and instead use the file specified.
Edit: Sample code takes input from input.in and writes to output.out.
#include <stdio.h>
int main(){
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
int n;
scanf("%d",&n);
printf("%d\n",n);
return 0;
}
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 9 years ago.
Improve this question
By using the man command I want to list the names of the files I have already created with extra information such as filesize, date of modification etc.
I know I have to use the man command possibly something like:
man ls | documents
But this would not seem to work. If anyone would know how to do this that would be great? Any help would be much appreciated.
You use man to read the contents of the manual, not list files.
Use ls to list your files.
Use ls -l to list files with extra information.
Use ls -la to list all files (including hidden) with extra information.