By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

clarify Me

ilikesuresh
P: 47
Hi

i have written this program to find the file information using stat structure.
When i try to display the mode it shows blank(nothing)
where is the problem lies here..
clarify me...



#include<stdio.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
struct stat buffer;
int status;
char *mode;
char temp[20];
int main()
{
memset(temp,'\0',20);
mode = temp;
status = stat("/export/home/config/suresh/matrix.c",&buffer);
printf("\nStatus-->%d",status);
if(status == -1)
{
perror(NULL);
exit(1);
}
mode = buffer.st_mode;
printf("\nNumber of links --> %d",buffer.st_nlink);
printf("\nFile Size --> %d",buffer.st_size);
printf("\nUser Id --> %d",buffer.st_uid);
printf("\nGroup Id --> %d",buffer.st_gid);
printf("\nMode --> %10.10s",temp);
return 0;
Sep 25 '07 #1
Share this Question
Share on Google+
7 Replies


P: 53
Hi friend,


May i know for what purpose you tend to print the Mode value?
If you want to use the mode value of the stat structure, You just use the following piece of code.
struct stat stbuf;

if(S_ISREG(stbuf.st_mode)){
printf("Regular file");
else if(S_ISDIR(stbuf.st_mode))
printf("directory
");
Sep 25 '07 #2

ilikesuresh
P: 47
Hi friend,


May i know for what purpose you tend to print the Mode value?
If you want to use the mode value of the stat structure, You just use the following piece of code.
struct stat stbuf;

if(S_ISREG(stbuf.st_mode)){
printf("Regular file");
else if(S_ISDIR(stbuf.st_mode))
printf("directory
");
Thanks for your reply.
I tried this one and working fine
But i want to know how the mode values looks likes (its in character or number thats all...)
Sep 25 '07 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
Hi

i have written this program to find the file information using stat structure.
When i try to display the mode it shows blank(nothing)
where is the problem lies here..
clarify me...



#include<stdio.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
struct stat buffer;
int status;
char *mode;
char temp[20];
int main()
{
memset(temp,'\0',20);
mode = temp;
status = stat("/export/home/config/suresh/matrix.c",&buffer);
printf("\nStatus-->%d",status);
if(status == -1)
{
perror(NULL);
exit(1);
}
mode = buffer.st_mode;
printf("\nNumber of links --> %d",buffer.st_nlink);
printf("\nFile Size --> %d",buffer.st_size);
printf("\nUser Id --> %d",buffer.st_uid);
printf("\nGroup Id --> %d",buffer.st_gid);
printf("\nMode --> %10.10s",temp);
return 0;
You have posted a C programming question in the Linux/Unix/BSD forum. You should be mindful of where you are posting.

Can one of the moderators of this forum please move this to the C/C++ forum?

Thank you!

Regards,

Jeff
Sep 25 '07 #4

ilikesuresh
P: 47
You have posted a C programming question in the Linux/Unix/BSD forum. You should be mindful of where you are posting.

Can one of the moderators of this forum please move this to the C/C++ forum?

Thank you!

Regards,

Jeff
Thanks for your comments
But the main thing here this program wrritten in Unix platform
And the syntax and the problem here i mentioned is only specific to Unix?BSD not ordinary C.
So I raise in Unix/BSD forum
I think that there is no mistake in this...
Sep 26 '07 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
Thanks for your comments
But the main thing here this program wrritten in Unix platform
And the syntax and the problem here i mentioned is only specific to Unix?BSD not ordinary C.
So I raise in Unix/BSD forum
I think that there is no mistake in this...
Regardless of the platform, the issue is still with your C code, is it not? I am a moderator in the Perl forum and Perl is coded on many platforms. You won't see any Perl questions here in the Unix forums or in the Windows forums for that matter, just because that is the platform that they are coding on.

Regards,

Jeff
Sep 26 '07 #6

drhowarddrfine
Expert 5K+
P: 7,435
I agree with the OP that this is a Unix specific question and should remain here.
Sep 26 '07 #7

numberwhun
Expert Mod 2.5K+
P: 3,503
I agree with the OP that this is a Unix specific question and should remain here.
My appologies then.

Regards,

Jeff
Sep 26 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.