473,729 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem in placing command line aruments(LPSTR) into **char

hi,

I am want copy the command line arguments from szCmdLine of
WinMain(HINSTAN CE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
int iCmdShow) into **char cmdLineParamete r. So that I can use
cmdLineParamete r in other functions. If any body knows pls help me

I am trying the following code sample:

char **cmdLineParame ter;
int k=0;
int WINAPI WinMain(HINSTAN CE hInstance, HINSTANCE hPrevInstance, PSTR
szCmdLine, int iCmdShow)
{
for (i = 0; i < strlen(szCmdLin e); i++)
{
// Now check for command-line arguments
if (strncmp(&szCmd Line[i], "-pw", strlen("-pw")) == 0)
{
cmdLineParamete r[k]=(char *)malloc(sizeof (char)*
strlen(&szCmdLi ne[i])));
strncpy(cmdLine Parameter[k],&szCmdLine[i],strlen(&szCmdL ine[i]));
k++;
continue;
}
if (strncmp(&szCmd Line[i], "-vpw", strlen("-vpw")) ==
0)
{
cmdLineParamete r[k]=(char *)malloc(sizeof (char)*
strlen(&szCmdLi ne[i])));
strncpy(cmdLine Parameter[k],&szCmdLine[i],strlen(&szCmdL ine[i]));
k++;
continue;
}
etc....
}
}
thanking u,
Nagesh

Dec 28 '05 #1
2 3125
pH
The code you're using there will cause memory faults, as you never
allocate memory for the array cmdLineParamete rs itself, only for the
strings its elements point to; so, you need something like
cmdLineParamete r = (char **)malloc(sizeo f(char *) * something), where
something is the number of arguments you are expecting.

Also, using strncmp() at every offset into szCmdLine is rather
inefficient; it might be better to use strtok or similar to split the
string at each space (or whatever) character, and then put the results
in your cmdLineParamete r array. You'd still need to allocate memory for
this array; to avoid over/under allocating the amount, you might want
to count how many spaces appear in the szCmdLine and allocate space for
that many parameters, and then copy tokens out of the string into the
array.

Dec 28 '05 #2
hi,
I followed ur tips. I could run without any problem.

thank u very much,
Wish u a happy new year,
Nagesh

Dec 30 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8255
by: Neil Morris | last post by:
Hi I have the following code that lists first names of people who's surnames are 'Morris'. What I am trying to do is search for first names that don't start at the beginning of the line ie. have the '' in the regExp object, but 'Neil' is matched even though it is next to(?) the start of line char(?) or should I say 'Neil' is the first 'word' of the string? here's the code <html>
6
3390
by: Ram Laxman | last post by:
Iam new bie to C++ programming.. I want to write a program which will read the Comma separated values(CSV) file column wise. For example: In a.txt: "TicketNumber","Phone","CarNumber" 10,20,30
6
2820
by: Dawn Minnis | last post by:
Hi (running Win xp and developing using Miracle C. Running applications in windows command prompt) I'm new to the group so be gentle with me. I am currently writing a C program to perform matrix by matrix (mxm) and matrix by vector (mxv) multiplication, so obviously one of my first considerations is to ask the user if they want an mxm or mxv multiplication performed. I have written the code below (this is a working snippet of the...
5
14035
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources... Updating references...
2
4838
by: Clodoaldo Pinto Neto | last post by:
Hi all, I'm trying to copy a table with a text field column containing a new line char to a file: ksDesenv=# create table page(line text) without oids; CREATE TABLE ksDesenv=# insert into page (line) values('1stline'||chr(10)||'2ndline'); INSERT 0 1
6
1628
by: kalyan.listsubs | last post by:
Hi, I have the below program which will simply write struct employee to a file (binary mode). The problem here is empid is writen to the file but the name (char name) is not written. I am using cygwin (gcc compiler) and use the following commands to compile & run respectively: gcc -o emp emp.c ../emp write -> this will create a file emp.out and write employee (Adam
0
2401
by: ipoxygen | last post by:
Hi, I do have 6 identical tables on six different databases (same server). I would like to merge them into one single table for reporting purposes. For the majority of the table it does work without a problem with following procedure: /* 100: NL 200: BE 300: UK 400: FR 600: SP
6
17527
by: rynato | last post by:
whatever code I put inside this IF statement: if ($_SERVER == 'POST') I get a parse error. Even 'print "something goes here"' doesn't work. Any ideas?
3
1605
by: Fabio | last post by:
Hi, Each OS has its new line chars: unix = \n mac = \r windows = \r\n Can I get the used one on the OS where php is running?
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.