Code:
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
int main (int argc, char const *argv[])
{
if (argc == 1)
printf("No parameters! Use --help to get more information.");
if (argc == 2 && argv[1] == "--help")
printf("Just test, you are free now.");
if (argv[1][0] == "-")
printf("This does not work?");
return 0;
}
Two questions:
1) How can I compare parameters to string, maybe I should use sprintf
and later try comparing? Or maybe there is direct way of doing it?
2) How can I get first char of the first parameter? (It's kinda hard
to understand how to write this)
Using gcc 4 version under Mac OS X. 18 1781
"david" <Da************ *****@gmail.com wrote in message
news:17******** *************** ***********@60g 2000hsy.googleg roups.com...
Code:
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
int main (int argc, char const *argv[])
{
if (argc == 1)
printf("No parameters! Use --help to get more information.");
if (argc == 2 && argv[1] == "--help")
printf("Just test, you are free now.");
if (argv[1][0] == "-")
printf("This does not work?");
return 0;
}
Two questions:
1) How can I compare parameters to string, maybe I should use sprintf
and later try comparing? Or maybe there is direct way of doing it?
2) How can I get first char of the first parameter? (It's kinda hard
to understand how to write this)
The compiler should give you a warning for the second and last. You are
comparing a character to a string. You need '-' to create a char constant,
strcmp() to compare
if( strcmp(argv[1], "-help") == 0)
{
}
When you've sorted this out you might like to see my options parser, on the
website.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
I understood the problem with string comparison, but how about the
last if, which makes gcc to give me warning: testas.c:13: warning:
comparison between pointer and integer
Can I access the certain char of that parameter or I should use some
strings commands to make this work?
argv[1] is a pointer to the char array in memory, *argv[1] should show
to the first char in that array, the same as *argv[1][0]. I am right
(It looks that I am not)
david
P.S. Thanks for the help.
david <Da************ *****@gmail.com writes:
I understood the problem with string comparison, but how about the
last if, which makes gcc to give me warning: testas.c:13: warning:
comparison between pointer and integer
The code is:
if (argv[1][0] == "-")
printf("This does not work?");
(you should quote enough to give context)
Can I access the certain char of that parameter or I should use some
strings commands to make this work?
You can get at the characters one by one if you like as arg[1][0] and
argv[1][1] etc. The error is with the "-" which is a string literal,
not a character. Use '-'.
argv[1] is a pointer to the char array in memory, *argv[1] should show
to the first char in that array, the same as *argv[1][0]. I am right
(It looks that I am not)
The last one is not right but *argv[1] is OK. *argv[1][0] is trying
to apply * to character (namely argv[1][0]).
--
Ben.
In article <db************ *************** *******@q70g200 0hsb.googlegrou ps.com>,
david <Da************ *****@gmail.com wrote:
>I understood the problem with string comparison, but how about the last if, which makes gcc to give me warning: testas.c:13: warning: comparison between pointer and integer
Can I access the certain char of that parameter or I should use some strings commands to make this work? argv[1] is a pointer to the char array in memory, *argv[1] should show to the first char in that array, the same as *argv[1][0]. I am right (It looks that I am not)
david
P.S. Thanks for the help.
I suggest you switch to a more friendly language, such as AWK.
(Where this sort of nonsense doesn't happen)
I can't switch (studying Software Engineering). I just started to
learn C and C++ and difference between them.
C looks a bit familiar to ASM after some time, but I still don't know
this well enough for now, but that should change in month or two. But
I still think that ASM is better for now (for small code, like base64,
crc and etc programs/code fragments)
I know about the else, I just wrote it for small example not thinking
much about if statements. Next time (if there will be one I will try
not to do this and write as much correct code as I can).
I am reading this group from Google, there could I find FAQ of this
group?
Malcolm McLean wrote, On 20/02/08 18:00:
>
"david" <Da************ *****@gmail.com wrote in message
news:17******** *************** ***********@60g 2000hsy.googleg roups.com...
>Code: #include <stdio.h> #include <strings.h> #include <stdlib.h>
int main (int argc, char const *argv[]) { if (argc == 1) printf("No parameters! Use --help to get more information.");
What if argc is 0? Yes, that *is* possible on any Unix like system,
which includes MacOS X
> if (argc == 2 && argv[1] == "--help") printf("Just test, you are free now.");
if (argv[1][0] == "-") printf("This does not work?");
return 0; }
Two questions: 1) How can I compare parameters to string, maybe I should use sprintf and later try comparing? Or maybe there is direct way of doing it? 2) How can I get first char of the first parameter? (It's kinda hard to understand how to write this)
The compiler should give you a warning for the second and last. You are
comparing a character to a string. You need '-' to create a char
constant, strcmp() to compare
if( strcmp(argv[1], "-help") == 0)
{
}
When you've sorted this out you might like to see my options parser, on
the website.
The OP is more likely to find the POSIX function getopt or the GNU
function getopt_long useful since he is almost certainly trying to
replicate their behaviour. For help with the POSIX getopt function the
OP should ask in comp.unix.progr ammer, possibly one of the GNU groups
for getopt_long.
--
Flash Gordon
"Flash Gordon" <sp**@flash-gordon.me.ukwro te in message
news:pq******** ****@news.flash-gordon.me.uk...
Malcolm McLean wrote, On 20/02/08 18:00:
>> "david" <Da************ *****@gmail.com wrote in message news:17******* *************** ************@60 g2000hsy.google groups.com...
>>Code: #include <stdio.h> #include <strings.h> #include <stdlib.h>
int main (int argc, char const *argv[]) { if (argc == 1) printf("No parameters! Use --help to get more information.");
What if argc is 0? Yes, that *is* possible on any Unix like system, which
includes MacOS X
>> if (argc == 2 && argv[1] == "--help") printf("Just test, you are free now.");
if (argv[1][0] == "-") printf("This does not work?");
return 0; }
Two questions: 1) How can I compare parameters to string, maybe I should use sprintf and later try comparing? Or maybe there is direct way of doing it? 2) How can I get first char of the first parameter? (It's kinda hard to understand how to write this)
The compiler should give you a warning for the second and last. You are comparing a character to a string. You need '-' to create a char constant, strcmp() to compare if( strcmp(argv[1], "-help") == 0) {
}
When you've sorted this out you might like to see my options parser, on the website.
The OP is more likely to find the POSIX function getopt or the GNU
function getopt_long useful since he is almost certainly trying to
replicate their behaviour. For help with the POSIX getopt function the OP
should ask in comp.unix.progr ammer, possibly one of the GNU groups for
getopt_long.
My options parser depends only on the standard library. The alternatives you
suggest may not be available on the OP's platform.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
david wrote, On 20/02/08 19:59:
I know about the else, I just wrote it for small example not thinking
much about if statements. Next time (if there will be one I will try
not to do this and write as much correct code as I can).
The more effort you put in to writing your code the more effort people
are likely to put in to helping you.
I am reading this group from Google, there could I find FAQ of this
group?
When I search for comp.lang.c FAQ in Google (rather than Google Groups)
it is the first hit. http://c-faq.com/
--
Flash Gordon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sharon |
last post by:
Hi,
Is it possible to check parameters against other parameters, as in:
<xsl:variable name="tableData">
<xsl:apply-templates
select="general/data/rows/row/fvalues"
mode="tableData" />
</xsl:variable>
(The parts I'm referring to are in capitals). Because this gives me no
|
by: Keeko |
last post by:
Actionscriptor needs help!
I have a working javascript function (getVar()) that extracts a variable
from a link and returns it. (tested with alert() works fine). But I am
unsure of how to right the following line.
document.write("<param name='flashVars' value=&{getVar(text)}>)
This is a param from an object tag (embedding flash) and i'm trying to
dynamically set the flashVars param, but this 1 line is killing me.
|
by: Daimy |
last post by:
I meet the same problem below, please help me!
Thanks!
//written by some one
I have developed a windows forms user control, which I am going to host in
Internet Explorer..
I am familiar with the security settings requirement inorder to do the
|
by: Michael.Suarez |
last post by:
The code in my DLL:
/// <summary>
/// db_task..file_master_list
/// </summary>
/// <param name="panConnection">
/// Pass the PanApp.Connection object by reference
/// </param>
/// <param name="source_id">
/// Default Value = 0
|
by: Michael.Suarez |
last post by:
So I wrote a DLL in 2.0. An example of one of the funtions is:
/// <summary>
/// db_task..file_master_list
/// </summary>
/// <param name="panConnection">
/// Pass the PanApp.Connection object by reference
/// </param>
/// <param name="source_id">
/// Default Value = 0
| |
by: John A Grandy |
last post by:
I have always extracted query string params assuming that I could specify
the param name case-insensitive :
string param = Request.QueryString;
Is there any scenario in which this would not work (i.e. case mismatch
between param-name used in query-string and param-name I specify in code) ?
Thanks.
|
by: Aussie Rules |
last post by:
Hi,
I have the Windows media object placed on a web page.
Since its not a .net component (its a com object) I have placed the code in
the html source of the page. The problem I am having is that I get the url
of the video file i want to play in the asp.net code (form_load event). How
do I pass this value into the html...
Ie :
|
by: Mark Rae |
last post by:
Hi,
For years I've been using the clwhois.exe app to check whether domains are
available or not and, if not, who owns them:
http://www.whoisview.com/products/clwhois/
Because this is a command line utility, it requires the
System.Diagnostics.Process class. It works well enough (code is below), but
I was wondering if anyone has a more efficient method. I'm aware that it's
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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,...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |