C++ [Sitemap] - HeapOverflow Computer Security Community & Forums : Heap Overflow.com

PDA

View Full Version : C++


Steve
05-07-05, 20:22
hi there

i have the following problem
i want to read multiple args through scanf and but them
out in main. my prob is that i want to use different args :-)
something like the main(char *args[]) function
where i can also pass different args through the command line

9 ################################
10 Ausgabe
11 Arg1: test
12 Arg2: test
13
14 #include "stdafx.h"
15 #include "stdio.h"
16 #include "string.h"
17
18 char buffer[100];
19
20 void insertarg(char *argv[]){
21
22 scanf("%s",buffer);
23 argv[0]=buffer;
24 scanf("%s",buffer);
25 argv[1]=buffer;
26 }
27
28 int main(){
29 char *my_argv[2];
30 insertarg(my_argv);
31 printf("Arg 1: %s\n",my_argv[0]);
32 printf("Arg 2: %s\n",my_argv[1]);
33 }
34
35 thanx a lot
36 hopeless
37

class101
05-07-05, 23:43
do you mean:

int main(int argc,char *argv[]) ?

if yes argc here is the number of arguments, program included.
and argv[], to select one, as argv[0] is always your program, argv[1] is the switch "-p" in DFind , etc...

class101
05-07-05, 23:45
and btw what do you wrote is C , not C++

Steve
06-07-05, 16:37
Hi there
now i use strncat and chain the arguments successively to the buffer.
Later in the main function i split them with strtok and assign them to my
various pointers.

thanx a lot
cya hopeless[/b]