setting environment variable using setenv [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 set and get the value of environment variable in Linux using C. Can anyone tell me how to use the setenv environment variable.
I want the environment value to be set to zero, and while using the getenv that environment value should be 0?

Try to use putenv() instead of setenv(). A little substrac of the manpage says:
"The setenv() function inserts or resets the environment variable name in the current environment list. If the variable name does not exist in the list, it is inserted with the given value. If the variable does exist, the argument overwrite is tested; if overwrite is zero, the variable is not reset, otherwise it is reset to the given value."
A question, when you said zero, you are talking about zero character right?. You have to put a string there.

Related

C Language error problem what's happening here? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 days ago.
Improve this question
check (https://i.stack.imgur.com/AHR2c.png) in this picture you can see problem
this is c language question in this question i put any character or string type value at run time it has to be show error but it is showing even why?
Whenever we try declare a variable before initializing it, It stores an undefined value which is unpredictable and varies from run to run, compiler to compiler and it is always recommended to initialize your variable.
And scanf function is a type-unsafe function and it does not check the type of the value which you are entering and of the value which you enter is not a integer like you try to store a string value in the integer type variable then it will assign some undefined value which is also unpredictable and it is a indication of that the value you have entered in Invalid.

How the string prints the name without termination symbol ;(semicolon)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
#include<stdio.h>
void main(){
if(printf("Hello World")){
}
}
this is editted which i copied from the compiler ...
Try this its truly working and print as Hello World
You have to remember that a function call is an expression, and that in C you can have any expression as the condition for an if statement.
Not sure what the problem is here.
printf() is just a function. It returns a value (an int that says how many characters were printed).
So when used as the controlling expression in an if, of course it's called ("evaluated") since the if needs to know the return value.
Calling printf() has the usual side-effect of generating output.
I've tried running this and got following Build messages
However, printf() returns the number of characters it has printed , Unless you put printf("") as condition, it will evaluate to be true. ;)
printf("Hello World") is an expression not statement, so you don't need semi-colon there.

Can you use operators to define the size of an array in C? [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
Right now I'm trying to write a program, and one part of the it involves expanding an existing array by copying values from a previous array into an array with a larger size.
The way I'm doing this by using an int variable which is defined in a previous point int the program by user input.
int[x] array;
int[x + 1] array2;
Will this work, or do I have to initialize a separate int variable with value of x + 1?
The correct syntax is:
int array[x];
int array2[x+1];
C 1999 and later supports this (with the value of x determined at run time), although it is optional in C 2011. Some compilers (of questionable quality) do not support it.
The space available for objects of this sort is typically limited to one to eight mebibytes or so, and that space must also serve for other program needs, so it should be used only for small arrays.

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.

C: Creating a given number of variables automatically [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
Is it possible to create a C-function that creates automatically a given number of variables? How are variables named?
Variables are an artifact of your source code. During runtime (which is when your function actually executes) there is only memory and registers. Maybe you want an array of a certain length?
The solution is to use array.
example:
//n is number of variables
int *var;
var= malloc(sizeof(int) * n);
variables are named var[0], var[1]....var[n-1]
If by "variables" you mean "global variables outside the scope of the function", and by "create" you mean "declare and define", then NO.
Do you mean like the register_globals 'feature' in PHP? Thank goodness, no.

Resources