LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2006, 06:25 PM   #1
hubabuba
Member
 
Registered: Jan 2002
Location: UK
Distribution: Slack 14.1
Posts: 193

Rep: Reputation: 30
Question storing octal value in char variable


Hi

I am trying to write a program that takes in two arguments: one - fle name, two - permissions in octal form (eg. 0644).
So far I know that for arguments I use:

int main(int argc, char **argv)

then, I want to use:

mode_t mode = argv[2];
int chmod(const char *pathname, mode_t mode)

so my problem is that somehow, I need char argv[2] to store the octal/mode_t value which will need to be assigned to the variable "mode" of type "mode_t". I can't get this to work, please help!

Thanks
 
Old 04-17-2006, 12:53 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Several ways:
Code:
  #include <stdlib.h>
  ...
  int istat, imode;
  istat = sscanf (argv[2], "%o", &imode);
  if (istat != 1)
    ...
... or ...
Code:
  #include <stdlib.h>
  ...
  long imode;
  imode = strol (argv[2], NULL, 8);
    ...
'Hope that helps .. PSM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python: converting a 3 character octal string into and ASCII char llama_meme Programming 1 07-06-2010 02:00 PM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 10:35 PM
Storing the result of execvp to a char array in C kponenation Programming 3 12-14-2005 05:45 PM
reading a char string of variable size in C introuble Programming 3 05-08-2005 01:07 PM
bash script to replace char in variable gmartin Programming 5 11-08-2004 01:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration