Integer expression assignment to a variable from string - C [closed] - c

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 5 years ago.
Improve this question
I'm programming an OS.
So I want to know how can an expression like (2*(7+8)-9)+2 can be initialised into variable using user defined function like extract() :
extract(char a[])
{
//some code
}
char expr[] = "(2*(7+8)-9)+2";
int value = extract(expr);
I'm doing this for variable initialisation from string.( Any tips/ideas/suggestions? )

StackOverflow has already covered the topic of Infix expression parsing and Recursive Decent parsing using C++ here. Read it over to understand the algorithm, then see if you can convert it to C. That will definitely be "fun" and teach you a little bit about C along the way.

Related

How to implement the printf function in risc-v? [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 3 years ago.
Improve this question
Here's the C representation of what I'm trying to do in RISC-V assembly:
printf ("x=%d\n", x);
https://godbolt.org/ is an interesting site. If you paste in c code, it can be transfered into others, such as RISC-V assembly. The sample c code is available from menie.org/georges/embedded/small_printf_source_code.html. It does work. Good luck.
Here is a very simple printf (actually only integers and strings and no advanced formatting)
https://godbolt.org/z/sgMVs7
It is not my code - it is tiny ptinf from the atolic studio. But it is a good base to implement something simple but more decent.

Displaying pointer's address in C, without using printf? [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 need to recode the printf function using only a handful of functions from the libc library, namely write, malloc and free and a few other basic ones. The only formatting tab that I am having trouble with is %p as I have no idea how to display it using the write function, as passing the address of my pointer to a function that prints strings resulted in empty output. I have also tried typecasting it to a char * and unsigned char * but that did not work either. I have looked online but only found solutions invloving forbidden functions so I am not even sure where to begin.

C: recognize variable type [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'm learning C. I wonder whether there is an instruction or command to recognize the type of the variable.
To be more practical: I have a program which works with integers, I want to show an error message if the user inserts a real number when running the program.
Hope you can help!
This is not part of the C standard, but GCC has the typeof keyword.
You have to be using the GCC compiler for it though.

How can I convert an array name to an array pointer in C? [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 8 years ago.
Improve this question
I have a list of arrays, each with its own descriptive name.
How can I create a pointer to a particular array just using the name (ie string) of the array?
If I understand correctly, what you mean and what you want, then you want something as Map, Dictionary etc. For example, look at this question: Quick Way to Implement Dictionary in C
The C programming language is somewhat of a "low-level" language. It doesn't natively have any introspection constructs.
The names you see/use are just labels that are converted to addresses by the compiler when building a static executable, so the running code has no way to look up things by variable name.

Need help locating a mistake in a single code line [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 8 years ago.
Improve this question
void find_best_match(char*currword, char(*)[]chosen_dict ,char*newWord,int length_of_dict)
I get "expected "," ,";" or ")" before "chosen_dict" " . I've revised the syntax multiple times , but can't locate the error. Any help would be appreciated :)
This does not make any sense:
char(*)[]chosen_dict
A correct declaration would be
char(*chosen_dict)[]
The pointer to an unknown-sized array is:
char (*chosen_dict)[]
Some people find the "spiral rule" helpful for understanding the declaration. Others prefer typedefs, and others yet just use cdecl to figure this stuff out.
As long as you don't need to declare arrays of function pointers to functions taking pointers to arrays in one line, you should be fine.

Resources