public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Borsos Zoltán <zoltan.borsos@sysdata.siemens.hu>
To: "'gcc@gcc.gnu.org'" <gcc@gcc.gnu.org>
Subject: stat problem ?
Date: Wed, 29 Mar 2000 22:27:00 -0000	[thread overview]
Message-ID: <C5A110B10A18D21184F100104B435721015B38D7@budg101a.sysdata.siemens.hu> (raw)

Hi everybody !

I'm new in this list and in C too.
I have written a small program that in one version dosen't work
but in the other does it. I'd like to ask the experts explain me the
difference between the programs.

I can compile both free from errors but when I let it run this version
give me the following message :

[main] D:\KOZOS\progik\c\exe\dirsiz_1.exe 1000 (0) handle_exceptions:
Exception:
 STATUS_ACCESS_VIOLATION
[main] dirsiz_1 1000 (0) handle_exceptions: Dumping stack trace to
dirsiz_1.exe.
core

// dirsiz_1.c

#include <dirent.h>
#include <sys/stat.h>
 

main(void) {

DIR *dp;
struct dirent *ep;
struct stat *st;
int rc;

dp = opendir ("./");
if (dp != NULL)
{
while (ep = readdir (dp)) 
{
rc=stat (ep->d_name,st);
if (S_ISDIR(st->st_mode)!=0)
	puts (ep->d_name);
else
	{
	printf ("Not a directory : ");
	puts(ep->d_name);
	printf("\n");
	}
}
(void) closedir (dp);
}
else
puts ("Couldn't open the directory.");
return;
}

-------------------------------------------------

This version works fine :

// dirsiz_2.c

#include <dirent.h>
#include <sys/stat.h>
 

main(void) {

DIR *dp;
struct dirent *ep;
struct stat st;
int rc;

dp = opendir ("./");
if (dp != NULL)
{
while (ep = readdir (dp)) 
{
rc=stat (ep->d_name,&st);
if (S_ISDIR(st.st_mode)!=0)
	puts (ep->d_name);
else
	{
	printf ("Not a directory : ");
	puts(ep->d_name);
	printf("\n");
	}
}
(void) closedir (dp);
}
else
puts ("Couldn't open the directory.");
return;
}

Thanks for the answers !
The answers please to my own address too.

Szambi

             reply	other threads:[~2000-03-29 22:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-29 22:27 Borsos Zoltán [this message]
2000-03-31 12:49 Greg Rigole

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C5A110B10A18D21184F100104B435721015B38D7@budg101a.sysdata.siemens.hu \
    --to=zoltan.borsos@sysdata.siemens.hu \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).