473,467 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Implementing Chmod command using c

Hi all,

I was trying to implement chmod command(UNIX) in c. While passing
arguments to the main function like :

-r for reading the file
-w for writing the file
How can I compare the second argument i.e argv[1] with something like
-r?
While running the program if I enter -r it should read the file.
So if(argv[1]=='-r') can't be done as we cant compare a pointer to an
integer. so Please suggest how to do this??
Thanks
Shastri

Feb 6 '06 #1
5 4289
Shastri wrote:

... While passing arguments to the main function like :

-r for reading the file
-w for writing the file
How can I compare the second argument i.e argv[1] with something like
-r?


if (strcmp(argv[1], "-r") == 0)
...

--
Peter

Feb 6 '06 #2
Shastri wrote:
Hi all,

I was trying to implement chmod command(UNIX) in c. While passing
arguments to the main function like :

-r for reading the file
-w for writing the file
How can I compare the second argument i.e argv[1] with something like
-r?
While running the program if I enter -r it should read the file.
So if(argv[1]=='-r') can't be done as we cant compare a pointer to an
integer. so Please suggest how to do this??

Check for '-', then test the following character.

--
Ian Collins.
Feb 6 '06 #3

"Shastri" <sa*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi all,

I was trying to implement chmod command(UNIX) in c. While passing
arguments to the main function like :

-r for reading the file
-w for writing the file
How can I compare the second argument i.e argv[1] with something like
-r?
While running the program if I enter -r it should read the file.
So if(argv[1]=='-r') can't be done as we cant compare a pointer to an
integer. so Please suggest how to do this??
Thanks
Shastri

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

In a main() like the above you can use multi dimentation array
such as ,argv[rows][coloums] along with counter argc inside a if statement.
Simply use loop iterations for rows and coloums to march through the array.
Hope that helps.
Feb 6 '06 #4
On 5 Feb 2006 16:52:23 -0800, "Shastri" <sa*****@gmail.com> wrote:
Hi all,

I was trying to implement chmod command(UNIX) in c. While passing
arguments to the main function like :

-r for reading the file
-w for writing the file
How can I compare the second argument i.e argv[1] with something like
-r?
While running the program if I enter -r it should read the file.
So if(argv[1]=='-r') can't be done as we cant compare a pointer to an
integer. so Please suggest how to do this??
You are looking for the strcmp function.

BTW, '-r' is a no-no. The ' delimiter is for a character constant
containing a single character. You want "-r" which defines a string
literal.

Thanks
Shastri

Remove del for email
Feb 7 '06 #5

"Barry Schwarz" <sc******@doezl.net> wrote in message
news:uc********************************@4ax.com...
On 5 Feb 2006 16:52:23 -0800, "Shastri" <sa*****@gmail.com> wrote:
Hi all,

I was trying to implement chmod command(UNIX) in c. While passing
arguments to the main function like :

-r for reading the file
-w for writing the file
How can I compare the second argument i.e argv[1] with something like
-r?
While running the program if I enter -r it should read the file.
So if(argv[1]=='-r') can't be done as we cant compare a pointer to an
integer. so Please suggest how to do this??


You are looking for the strcmp function.

BTW, '-r' is a no-no. The ' delimiter is for a character constant
containing a single character. You want "-r" which defines a string
literal.


Yeah, I don't think that will work too well either as written...
How about: if(strcmp(argv[1], "-r") == 0)
or better yet, use getopt() if it's available on your platform.

Mark
Feb 7 '06 #6

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

Similar topics

5
by: Daniel | last post by:
Hi, From what I read from the PHP manual, chmod on a Windows platform should have no effect, and that seems totally normal (unless someone on sourceforge has a windows port of that!). I...
6
by: Ask Josephsen | last post by:
Hi NG If I write the following: <?php $file="myfile.JPG"; if ( getmyuid()==fileowner ( $file ) ) { chgrp ( $file, getmygid() ); chown ( $file, getmyuid() );
1
by: Xuan Yuan | last post by:
I'm using Windows XP Professional and have no FTP installed. Instead, I use Command Promt. I need to CHMOD a PHP file, so I type "CHMOD 775 file-path",but get "'CHMOD'is not recognized as an internal...
1
by: James Colannino | last post by:
Ok, so now I have a very interesting problem, this time related to os.chmod. I have the following in a text file: 0600. My script reads that number as a string and converts it to an integer for...
47
by: frizzle | last post by:
Hi, I am at the base of an FTP thingy i'm building, and i noticed that it would only work if i chmod the folder 777, i thought to remember correctly that previously on another site chmod 744 was...
3
by: Rik | last post by:
Hello, first of all, my provider sucks, newsserver is down for the #nth time now, offcourse when I have an urgent question.... So this will be me first time using Google Groups, forgive me if...
4
by: sajithamol | last post by:
In Unix I frequently change the file permissions by using the chmod command. I use 755 and 777 most of the time but don't have clear idea about these numbers. Tried googling but didn't find proper...
1
by: lawrence k | last post by:
I've a simple script to transfer some files from one domain to another, with both domains living on the same server. The files in both directories are already chmod 777. Yet after transfer, I try...
5
by: petershaman | last post by:
Hi I have a gorgeous flash image gallery, it would work perfectly fine but there's a small problem I can't upload anything thru it's upload script, since I'm getting an error 403. It's so because...
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
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,...
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
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,...
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...
1
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.