473,414 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how i can print the values of argv[] under unix environment.Plz help me

hai

i have a problem i con't able to print the values of argv[]

int main(int argc, wchar_t* argv[])
{

return o;

}

how i can print the values of argv[] under unix environment.Plz help me

Nov 14 '05 #1
13 5994
Hai

when i compile the cpp file(cmdargs.cpp) i attached the output below
the program

int main(int argc, wchar_t* argv[])
{

std::wcout<<L"Name of the Program is
"<<*argv[0]<<std::endl;
std::wcout<<L" Argument Count "<<argc-1<<std::endl;
for(int args=1;args<argc;args++)
{
std::wcout<<L"Argument "<<args<<" is "<<
*(argv[args])<<std::endl;
}
return 0;
}
output :
~~~~~~~~~~~~~~
Name of the Program is <----------------only this much...........

-->

-->

-->

-->

#include<iostream>
#include <stdlib.h>
int main(int argc, wchar_t* argv[])
{
std::cout<<"Name of the Program is
"<<*argv[0]<<std::endl;
std::cout<<" Argument Count "<<argc-1<<std::endl;
for(int args=1;args<argc;args++)
{
std::cout<<"Argument "<<args<<" is "<<
*(argv[args])<<std::endl;
}
return 0;
}
cmdargs asd fgh jkl

output :
~~~~~~~~~~~~~~

Name of the Program is 1668113505
Argument Count 3
Argument 1 is 1634952192
Argument 2 is 1718052864
Argument 3 is 1785424896

-->

-->

-->

-->
here i got some nos but i want the strings how i can print the
values..plz help me
Thanks in advance
Vinu

Nov 14 '05 #2
If you use printf, You must specifie "l" flag:

#include <stdio.h>

int main(int argc, wchar_t** argv) {
int i;
for (i=0; i<argc; i++)
printf("%sl\n", argv[i]);
fgetc(stdin);
return 0;
}

Nov 14 '05 #3
why it is not giving the output

in 2'nd case it i giving the nos

i want to use cout...

can u help me out in this matter ?

Nov 14 '05 #4
Vinu wrote:
#include<iostream>


news:comp.lang.c++

--
pete
Nov 14 '05 #5
Vinu wrote:
why it is not giving the output

in 2'nd case it i giving the nos

i want to use cout...

can u help me out in this matter ?


Post with proper context/quote is much appreciated.

If you want to use c++ , try comp.lang.c++(.moderated)?

Krishanu
Nov 14 '05 #6

Vinu wrote:
why it is not giving the output

in 2'nd case it i giving the nos

i want to use cout...

can u help me out in this matter ?


comp.lang.c++ should have been the place to ask this question. Anyways,
use

for(int args=1;args<argc;args++)
{
cout<<"Argument "<<args<<" is "<<argv[args]<<endl;
}

You need a pointer to a string and argv[args] is a pointer to the
args'th argument.

regards,
vijay.

Nov 14 '05 #7
Hello vijay
int main(int argc, wchar_t* argv[])
{
std::cout<<"Name of the Program is
"<<*argv[0]<<std::endl;
std::cout<<" Argument Count "<<argc-1<<std::endl;
for(int args=1;args<argc;args++)
{
std::cout<<"Argument "<<args<<" is "<<
*(argv[args])<<std::endl;
}
return 0;
}

output :
~~~~~~~~

-->cmdargs asd fgh jkl
Name of the Program is 0xffbefd18
Argument Count 3
Argument 1 is 0xffbefd20
Argument 2 is 0xffbefd24
Argument 3 is 0xffbefd28

i changed my prog see one thing *argv[args] is also gives a pointer
wchar_t* argv[]

Vinu

Nov 14 '05 #8
On Wed, 04 May 2005 04:52:00 -0700, Vinu wrote:
hai

i have a problem i con't able to print the values of argv[]

int main(int argc, wchar_t* argv[])
In standard C the type of argv should be char ** which can be written in
a parameter list as char *[] (i.e. char *argv[])

{

return o;
}
how i can print the values of argv[] under unix environment.Plz help me


Here is a simple example:

#include <stdio.h>

int main(int argc, char *argv[]) {
int i;

for (i=0; i<argc; i++)
printf("%s\n", argv[i]);

return 0;
}

Nov 14 '05 #9
here it is not a wide char i want a unicode support cmd argumentts ie
wchar_t* argv[]
thanks

Nov 14 '05 #10
In article <11**********************@o13g2000cwo.googlegroups .com>
Vinu <vi*********@yahoo.com> wrote:
here it is not a wide char i want a unicode support cmd argumentts ie
wchar_t* argv[]
thanks


Your question (from the subject line) was about printing argv.
Presumably this means "the argv passed to main upon program startup".
(Your sample code was then in C++ rather than C, suggesting that
either you are not sure which language you are using, or that you
posted to the wrong newsgroup, or perhaps even both. Note that
when using "google groups", you are using Google's access portal
to the USENET newsgroup system. For the most part, USENET has
absolutely nothing to do with Google.)

With one exception, an implementation that passes "wchar_t **"
instead of "char **" as the second argument to the initial call to
main() is *not* a strictly conforming ANSI/ISO C implementation.
The exception occurs if that implementation makes wchar_t synonynous
with plain char, so that "wchar_t **" and "char **" are actually
the same type.

In any case, it is pretty silly to attempt to use wchar_t for argv.
(Only Microsoft would do something that dumb... :-) ) Use UTF-8.
It Just Works.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #11
"Vinu" <vi*********@yahoo.com> writes:
here it is not a wide char i want a unicode support cmd argumentts ie
wchar_t* argv[]
thanks


It's difficult to tell what you're talking about if you don't provide
any context.

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

The standard declaration for main is "int main(void)" or
"int main(int argc, char **argv)". An implementation may allow
other declarations, but anything other than the above is non-portable.

If you want to pass Unicode strings into your main program, you can
either use a method other than argc and argv or encode the Unicode
strings so they're representable as arrays of char <OT>UTF-8,
perhaps?</OT>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #12
Thanks for your suggestion and advice. I will try to redefine the
problem statement.

The application on Solaris Sparc expects wide characters for its
processing. One of the way of passing the wide characters will be pass
it through the 'int main(int argc, wchar_t* argv[])'. Is there any
alternative way of doing it?

While using the former way and passing the command line arguments to
the main function, we got bus error core dump while trying to access
the command line arguments as wide character strings.

Trying to print passed arguments to main usin wcout will print some
unsigned number instead of unicode string.

Are we doing any thing differently?

We have also tried to change main to wmain but it gives 'undefined
symbol main' 'ld: fatal: Symbol referencing errors. No output written
to <application name>' during linking.

Can you suggest standard way of doing it on Sun Solaris Sparc? We are
using gcc 3.4.2 .

Nov 14 '05 #13
"Vinu" <vi*********@yahoo.com> writes:
Thanks for your suggestion and advice. I will try to redefine the
problem statement.

The application on Solaris Sparc expects wide characters for its
processing. One of the way of passing the wide characters will be pass
it through the 'int main(int argc, wchar_t* argv[])'. Is there any
alternative way of doing it?
What makes you think that you can declare main like that and have it
work? C's main() function takes two arguments, int argc and
char **argv (or, equivalently, char *argv[]).

If you declare it to take different types of arguments, it's quite
possible that the compiler won't complain, but when environment
invokes your program it will still attempt to pass it an int and a
char**. In effect, you're lying to the compiler. What happens next?
While using the former way and passing the command line arguments to
the main function, we got bus error core dump while trying to access
the command line arguments as wide character strings.
That's right, you get undefined behavior.

[...]
We have also tried to change main to wmain but it gives 'undefined
symbol main' 'ld: fatal: Symbol referencing errors. No output written
to <application name>' during linking.
That's right, because "wmain" is not a standard identifier in C.
Can you suggest standard way of doing it on Sun Solaris Sparc? We are
using gcc 3.4.2 .


There may be no way to do what exactly what you're trying to do. A
compiler is allowed to support declarations for main() other than the
standard ones, but as far as I know gcc does not.

If you want to get Unicode strings into your program, you'll just have
to find a different way to do it. The most obvious is to use a UTF-8
encoding.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #14

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

Similar topics

1
by: Stuart D. Gathman | last post by:
I need to be able to obtain the real argv (not the script name). The application is writing a CUPS backend in python. For some reason, CUPS decided to pass the URI as argv (perhaps to ensure that...
6
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
3
by: devlanguage | last post by:
Hi, The string " which is part of the argv input is removed. // test input : ./a.out dev "query" // actual output : query output // expected output : "query" output #include...
13
by: James | last post by:
consider : int main (int argc, char * argv ) { } In exec (2) ; Whose arguments which are passed to main. What is the maximum size of the string. argv = "hello........." ;
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
32
by: mnaydin | last post by:
Assume the main function is defined with int main(int argc, char *argv) { /*...*/ } So, is it permitted to modify the argv array? The standard says "The parameters argc and argv and the strings...
9
by: cniharral | last post by:
Hi, I'm interested in printing out coloured lines of my application and I don't know what to use. Can anybody give me an idea?? Regards. Carlos Niharra López
7
by: william | last post by:
I wonder how 'main(int argc, char ** argv)' is implemented? How does it get the string literals separated by whitespace from the stdin stream? And is there any difference between 'char**' and...
2
by: garic | last post by:
Hi Everyone, I've been asked to update a windows application to be able to read in some command line input. I added code to handle wrong inputs by printing out usage information to screen or when...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...
0
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...

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.