argv

Are there any other arguments that main() can accept?

…衆ロ難τιáo~ 提交于 2019-12-10 16:45:41
问题 I recently came across the following in my searches regarding environment variables in C: int main (int argc, char *argv[], *char *envp[]) I have searched around and can't find anything conclusive regarding my question. What are all of the available arguments that main() can accept? 回答1: The C99 and C11 draft standards allow for implementation defined set of parameters to main , these parameters are going to be specific to those systems( non-portable ). From section 5.1.2.2.1 : [...]or in

parsing argc and argv in c++

孤人 提交于 2019-12-10 15:25:44
问题 I want to learn more C++... Usually I make a for loop to parse argv, and I wind up with a bunch a C-style strings. I want to do something similar in C++, but preferably without reading from /proc/whatever. At first, I tried to convert the C-style string to a C++ style string without results... The frustrating bit is that everyone on SO seems to want to know how to go the other way, which is what c_str() is for. What's a good C++ way to do this (ie parse argv)? Also, one note, I'm looking for

Passing Argument 1 discards qualifiers from pointer target type

非 Y 不嫁゛ 提交于 2019-12-10 01:55:01
问题 My main function is as follows: int main(int argc, char const *argv[]) { huffenc(argv[1]); return 0; } The compiler returns the warning: huffenc.c:76: warning: passing argument 1 of ‘huffenc’ discards qualifiers from pointer target type For reference, huffenc takes a char* input, and the function is executed, with the sample input "senselessness" via ./huffenc senselessness What could this warning mean? 回答1: It means that you're passing a const argument to a function which takes a non- const

How to call correctly getopt function

蹲街弑〆低调 提交于 2019-12-09 18:57:10
问题 Errors while calling int getopt function from http://code.google.com/p/darungrim/source/browse/trunk/ExtLib/XGetopt.cpp?r=17 `check.cpp: In function ‘int main()’:` check.cpp:14:55: error: invalid conversion from ‘const char**’ to ‘char* const*’ [-fpermissive] /usr/include/getopt.h:152:12: error: initializing argument 2 of ‘int getopt(int, char* const*, const char*)’ [-fpermissive] #include <iostream> #include <cstring> #include <string> #ifdef USE_UNISTD #include <unistd.h> #else #include

Python Popen sending to process on stdin, receiving on stdout

柔情痞子 提交于 2019-12-09 15:50:09
问题 I pass an executable on the command-line to my python script. I do some calculations and then I'd like to send the result of these calculations on STDIN to the executable. When it has finished I would like to get the executable's result back from STDOUT. ciphertext = str(hex(C1)) exe = popen([sys.argv[1]], stdout=PIPE, stdin=PIPE) result = exe.communicate(input=ciphertext)[0] print(result) When I print result I get nothing, not None, an empty line. I'm sure that the executable works with the

Segmentation fault (core dumped) when using fscanf to read into a pointer

霸气de小男生 提交于 2019-12-09 04:02:17
问题 I'm trying to use fscanf to read and print every character on the screen, but I'm getting a segmentation fault (core dumped) when I run the program. Here's my code: #include <stdio.h> main(int argc, char * argv[]) { int *a ; FILE *input; if (argc>=2) { input= fopen(argv[1],"r"); if (input!=NULL) { while (feof(input)==0) { fscanf(input,"%d\n",a); printf("%d\n",*a); } fclose(input); } else { printf("Error!\n"); } } } I provide the file as an argument, like this: ./myprog input.txt The file

Argument is URL or path

故事扮演 提交于 2019-12-08 17:28:38
问题 What is the standard practice in Python when I have a command-line application taking one argument which is URL to a web page or path to a HTML file somewhere on disk (only one) is sufficient the code? if "http://" in sys.argv[1]: print "URL" else: print "path to file" 回答1: Depends on what the program must do. If it just prints whether it got a URL, sys.argv[1].startswith('http://') might do. If you must actually use the URL for something useful, do from urllib2 import urlopen try: f =

Why is argv (argument vector) in C defined as a pointer and what is the need for defining its zeroth as the program name?

安稳与你 提交于 2019-12-07 17:10:00
问题 #include <stdio.h> int main(int argc, char *argv[]) { int i; for(i=1;i<argc;i++) printf("%s%s", argv[i], (i<argc-1)? " ":""); printf("\n"); return 0; } Given above is a simple C program that outputs command line inputs. Here argc is the argument counter. argv is said to be an array that contains arguments. My question is: why does it define as a pointer to a character array instead of a normal array? Also what is the need for defining its zeroth element (argv[0]) as the name by which the

QApplication app(argc, argv)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 12:46:39
问题 I noticed that the main.cpp in a Qt application has to contain the following line: QApplication app(argc, argv); I know that argc is the number of command-line arguments, and argv is that array list of command-line arguments. But, the question in my mind is: what are those arguments I'm passing to the constructor and at the same time cannot explicitly see? What is working behind the scences out there? Thanks. 回答1: There are no hidden arguments. You can explicitly see every argument- argc,

Find argc and argv from a library

感情迁移 提交于 2019-12-07 10:40:53
问题 How do I find a program's argc and argv from a shared object? I am writing a library in C that will be loaded via LD_PRELOAD . I've been able to find the stack two different ways: Read rsp via inline __asm__ call. Read /proc/<pid>/maps and parse the entry for stack. I can then create a pointer, point it at the stack segment, then iterate through looking for data. The problem is I can't figure out an efficient way to determine what bytes are argc and the pointer to the pointer to the argv