fopen function in C + write into file [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to write some data into a file. But I have too many data and each one should be named through a certain structure depending on the number of nodes and number of edges each data file has.
For example: for a data having 10 nodes and 20 edges, its name will be s_10_20.txt
for a data having 14 nodes and 30 edges, its name will be s_14_30.txt
the structure I'm following is: s_numOfNodes_numOfEdges.txt
(knowing that numOfNodes and numOfEdges are already scanned from the data file.)
The code I wrote is:
FILE *fp;
fp=fopen("s_%d_%d.txt",numOfNodes,numOfEdges,"w+");
This is giving me the following errors:
passing argument 2 of fopen makes pointer from integer without a cast
too many arguments to function fopen
How can I write it in any other way?

sprintf function can help you.
char file_name[MAX_PATH];
sprintf(file_name, s_%d_%d.txt",numOfNodes, numOfEdges);
fopen(file_name, "w+");

Related

Analyzing Part of a String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm new to C and I have an assignment where I have to build a dictionary (Linked List in a way). Basically the user inputs several words,year and their definition this:
Example:
love_#_2004_#_LOVING
trade_#_2001_#_INVEST
etc...
And basically I need a function to scan the definition (Ex: INVEST)
and gives me the word trade.
If the definition is related to more than only one word to give me back all the words it relates to.
What sort of a function do I need to scan these strings?
If the word you search is always the last one and the formatting is always the same, then use strtok with _ and copy the last entry, which holds the string you are looking for.

How can i extract a yuv frame from given yuv 4:2:0 file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am new to this video processing.I have assigned a task of extracting a frame from a given yuv 4:2:0 file which is in QCIF format. basically I am using c program for this.
HELP me in coding
QCIF is a raw collection of pixels composed of what are called luma, cb, cr in the following array format.A luma frame is composed of 176x144 luma samples, followed by 88x72 cb samples followed by 88x72 cr samples. Reference
unsigned char luma[176][144];
unsigned char cb[88][72];
unsigned char cr[88][72];
Here you can find code that is used to read qcif file format.

fopen() leading to a segmentation fault [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have the file name of a file stored in char *names. When I use fopen(&names[0],"r"), I am receiving a seg fault error. Why is this happening and how can I fix it?
You already have a pointer to char as "names", so you could simplify that.
You can just pass that into fopen().
So as follows:
char * names = "/home/user/test.txt";
FILE * file = fopen(names, "r");
For the seg fault, we'd probably need to see what's in "names" or what it points to.

read file in a specific region line by line in file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a text file where every row has the format
A B:C
I want to read it using C language, but all i want to get in every line is what comes after the ':'. In other words I want to get only the C value in every line of the file, but all I want to do is read the file line-by-line and get every row's values.
Any idea to do that?
open the file for reading
fp = fopen("file.txt" , "r");
Use fgets() to read the line
fgets (str, MAX_LENGTH, fp);
Use Strtok to break according to ":"
ptr = strtok(str,":");
Read file line by line by using fgets()
fgets(line,MAX_SIZE,file_stream);
And use strchr(), to get the position from where C starts
char *ptr=strchr(line,':'); //ptr points to the : location
//now if you Move ptr location next to ':' ptr points to C
printf("C=%s",ptr+1);
And with out using additional pointer, You can do like this
printf("C=%s",strchr(line,':')+1);
Repeat these steps until reaching end of file. By checking the return value of fgets() against NULL.
Note: In this A B:C , if A or B consists : then You need to Apply logic accordingly.
You can also use strrchr()

C programming structure access [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I found this line in Linux Audio drivers soc-core.c inside sound folder:
int regsize = codec->driver->reg_word_size * 2;
Can anybody please explain the meaning of * 2?
Multiply the contents of codec->driver->reg_word_size by 2. I guess this is a translation between size in words to size in bytes.
Multiplies that value by 2. That's all it does
Well, I can just guess, but it looks like this:
codec is a pointer to a structure, which has a pointer to another structure in driver, which has a member variable reg_word_size (which it seems is, like the name says, the size of a register word). This value gets doubled (*2).
This could be, like the other answer says, a conversion between bytes and words. However, it could probably also just mean that this regsize should be twice as big as the reg_word_size.

Resources