Do what `which` does in bash but in C [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
What's a linux or posix C function to find the executable the same way Bash looks for an executable when you type it? I think which bash command does the same thing at least very similar. So if I give the function argument "ls" it returns "/bin/ls" for example looking into $PATH on the fly.

I examined the source code of the following commnads.
Both functions parse and search the environment variable PATH on their own.
which
char*
extract_colon_unit (char const* string, int* p_index)
execlp
static int
__execvpe_common (const char *file, char *const argv[], char *const envp[],
bool exec_script)
I guess there is no C function to search for commands.

Related

how read a .C file ( from wavtoccode software)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 months ago.
Improve this question
Convert or read a .C to wav
Hello,
for an IRL game (like an escape game) I want my players to find a .c file (i did it with WavToCode) and find a way to play it to hear the original Wav file.
How can I do?
Is there software for this?
Or another best way to read/convert file (.txt,.hex, etc) to audio ?
thank you
Use https://speechify.com/text-to-speech-online
Example:
char *duplicateString(const char *str)
{
char *newstring = malloc(strlen(str) + 1);
if(newstring) strcpy(newstring, str);
return newstring;
}
https://storage.googleapis.com/speechify-soundbite.appspot.com/audio/23d03d95cdd74d52cd96ba79b565522cd2d9909ef903a79bef3dc65a51ce365e.mp3?cb=1668103054800

How to get a list of C code functions ordered by length? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm analyzing a big chunk of C code and would like to split it into modules. Is there a way to automatically generate a list of C functions, starting with the ones that are the longest?
With the GNU userland (e.g. on Linux) you can use nm -S --size-sort object.o to get a list of symbols sorted by size from an object file. This should be approximately proportional to source code length.
If we can assume that the line with a function declaration is not indented, ends with { and the function definition ends with a non-indented }, this Python snippet can help:
#!/usr/bin/python
import sys
started = None
started_line = None
for lineno, line in enumerate(sys.stdin):
if line.startswith(' '):
continue
if line.strip().endswith('{'):
started = lineno
started_line = line.rstrip()
if line.strip().endswith('}'):
print("%s\t%s" % (lineno - started, started_line))

memset causes array underflow, how to detect that [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Lately I have noticed this kind of bug:
#define ELEMENTS 20
BOOL array[ELEMENTS];
void foo()
{
memset(array,0, ELEMENTS); /* BOOL isn't 1 byte but 4 bytes long */
}
How to detect memset underflows? Most of static,dynamic analysers can find only overflows. One which is able is PVSStudio. http://www.viva64.com/en/d/0101/print/.
Any free/open source alternatives ( preferably Windows but Linux also can be )?
Visual Studio 2012 analysis - failed.
Clang analyzer - failed.
Cppcheck - failed.
You cannot detect this without external tools like Valgrind, but you can avoid the need to detect it.
Scale to the size of the array's element:
memset(array, 0, ELEMENTS * sizeof array[0]);
Or if you can make sure array isn't a pointer (as per your code snippet) just do:
memset(array, 0, sizeof array);
The most simple way to avoid this is to consequently initialise all variables on definition:
BOOL array[ELEMENTS] = {0};

C - Why the size_t is unrecognized in eclipse? [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
In eclipse it don't recognize the type size_t, it write error on it and a message uknown type name 'size_t',
it is written right
size_t comes from stddef.h standard header file. You have to include it. You can also get it from stdio.h where it is also declared.

Tool to explain C code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I remember from some time ago reading about a commandline tool that explains C code, does anyone know what it might be named?
Perhaps you mean cdecl, a program that can translate complicated declarations to English and back?
e.g.
cdecl> explain int (*(*foo)(int ))(float )
declare foo as pointer to function (int) returning pointer to function (float) returning int
If you mean explaining then I think the answers already been given. If you mean looking for potential problems then there's lint and its variants, first stop in any code review.
http://en.wikipedia.org/wiki/Lint_programming_tool
Edit:
C/C++ Free alternative to Lint?
HTH

Resources