473,941 Members | 30,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wrong print

Hi!

This is a piece of a code I wrote. It was perfectly working but now it
is giving me some problems I can not understand.
I scan a directory (ss_data) and I count its alaments. then I print the
name of each file in the directory before opening it.Even if the names
of the files are stored correctly in the memory the program prints the
letter 'E'(the files are named differently,
e.g.traind05c1_ _a.1.1.1.3.fast a). The program correctly opens the files
but it does not print the names. Anybody can help?

Thank you in advance,

Chiara

#include <string.h>
#include <stdio.h>
#include <dir.h>
#include <dirent.h>
#include <stdlib.h>
#include <alloc.h>
#include <math.h>

char **strings,*line ;
int n_seq=0;
int max_line_len = 1024;
char **Amm,**Pss;
int** amm_comp,*y_cla ss,*y_fold,**ss _descriptor;
char** SS;
int** L,**range;
int n_files,n_el,ma x_length;
void generateSeq(int max_l,char* seq,int seq_len);
char* readline(FILE *input);
void scandir(char *dirname);
void analyzePss(char * pss,int ind);
int SearchSequence( char* seq, char* in);
int SearchRange(int * seq,int l, int low, int up);

void scandir(char *dirname)
{
DIR *dir;
FILE*fp;
char s[MAXPATH],amm,pss;
struct dirent *ent;
float pC, pH,pE;
int index,i,h,k=0,m ax_l,n=0;

dirname="ss_dat a";

if ((dir = opendir(dirname )) == NULL)
{
perror("Unable to open directory");
exit(1);
}
while ((ent = readdir(dir)) != NULL) //reads the directory counting
the number of files
{
if(strlen(ent->d_name)>5)
n_files++;
}

...
rewinddir(dir);
h=0;
while ((ent = readdir(dir)) != NULL)//reads the name of each file in
the directory
{
if(strlen(ent->d_name)>5)
{
printf("%d:%s\n ",h,ent->d_name);

.....
...

Nov 15 '05 #1
2 1709
chiara wrote:
Hi!

This is a piece of a code I wrote. It was perfectly working but now it
is giving me some problems I can not understand.
I scan a directory (ss_data) and I count its alaments. then I print the
name of each file in the directory before opening it.Even if the names
The C programming language does not know anything about directories, so
you must be using non-standard libraries. We only deal with the standard
language and libraries here. Still, I'll check your code in case there
is anything wrong with the standard bits...
of the files are stored correctly in the memory the program prints the
letter 'E'(the files are named differently,
e.g.traind05c1_ _a.1.1.1.3.fast a). The program correctly opens the files
but it does not print the names. Anybody can help?

Thank you in advance,

Chiara

#include <string.h>
#include <stdio.h>
The above are standard.
#include <dir.h>
#include <dirent.h>
The above two headers are not part of the C standard, they could be from
some form of Unix, so comp.unix.progr ammer might be worth investigating,
after checking their FAQ and a few days worth of posts.
#include <stdlib.h>
Another standard header.
#include <alloc.h>
A very suspicions non-standard header. Are you really sure it is
something you need?
#include <math.h>

char **strings,*line ;
int n_seq=0;
int max_line_len = 1024;
char **Amm,**Pss;
int** amm_comp,*y_cla ss,*y_fold,**ss _descriptor;
Putting the * (or **) on the type is generally considered bad style,
since it only applies to the first variable, not all the variables.
char** SS;
int** L,**range;
int n_files,n_el,ma x_length;

void generateSeq(int max_l,char* seq,int seq_len);
char* readline(FILE *input);
void scandir(char *dirname);
void analyzePss(char * pss,int ind);
int SearchSequence( char* seq, char* in);
int SearchRange(int * seq,int l, int low, int up);

void scandir(char *dirname)
{
DIR *dir;
FILE*fp;
char s[MAXPATH],amm,pss;
struct dirent *ent;
float pC, pH,pE;
int index,i,h,k=0,m ax_l,n=0;

dirname="ss_dat a";

if ((dir = opendir(dirname )) == NULL)
Problems with opendir don't belong here.
{
perror("Unable to open directory");
exit(1);
1 is a non-standard value for exit.
}
while ((ent = readdir(dir)) != NULL) //reads the directory counting
the number of files
Please don't use // style comments when posting to Usenet.
{
if(strlen(ent->d_name)>5)
n_files++;
}

...
Not posting a complete compilable program that exhibits your problem is
a very silly thing to do. Since you don't know what the problem is how
do you know that it problem is not in the code you have excluded?
rewinddir(dir);
You do realise that in a multi-tasking multiuser system a new file could
have been created by now, or one of the old file deleted, don't you?
h=0;
while ((ent = readdir(dir)) != NULL)//reads the name of each file in
the directory
{
if(strlen(ent->d_name)>5)
{
printf("%d:%s\n ",h,ent->d_name);

....
...


My best guess is that there is something wrong in the code you have not
posted or something wrong in your use of a non-standard C library. I
suggest that if I am correct and you are using a Unix variant you try in
comp.unix.progr ammer where Unix specific libraries are on topic, unlike
here. Before posting for the first time to a group ALWAYS read the FAQ
and at least a few days worth of posts to find out what is acceptable on
the group. If you don't understand something in the FAQ then tell people
which part of the FAQ you have problems with or they might assume that
you have not read it and just tell you to go read it. Also, post a
COMPLETE example that exhibits the problem, not something with
quantities of code missing. To get the example down to a sensible size
delete the code that you believe is not relevant to the problem and then
*test* to see that the problem still exists, often this exercise itself
will identify that the problem is NOT where you thought and might enable
you to solve it.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #2
Flash Gordon wrote:
chiara wrote:
Hi!

This is a piece of a code I wrote. It was perfectly working but now it
is giving me some problems I can not understand.
I scan a directory (ss_data) and I count its alaments. then I print the
name of each file in the directory before opening it.Even if the names

The C programming language does not know anything about directories, so
you must be using non-standard libraries. We only deal with the standard
language and libraries here. Still, I'll check your code in case there
is anything wrong with the standard bits...


<snip>

Problems with opendir don't belong here.
{
perror("Unable to open directory");
exit(1);

1 is a non-standard value for exit.


The OP may be interested to know that EXIT_FAILURE
is an option here (from <stdlib.h>). EXIT_SUCCESS
and 0 have the same meaning.

--
imalone
Nov 15 '05 #3

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

Similar topics

5
1874
by: Fendi Baba | last post by:
Hi everyone, I am new to php. I am using a piece of code which is testing if a certain variable is <=0. and the code is written as follows: $lc_align = 'center'; if ($listing<=0) { $lc_text = tep_image_button('button_buy_now_na.gif', IMAGE_BUTTON_BUY_NOW_NA) . '&nbsp;'; } else { $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF),
9
2657
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php'; global $LOGINDIR;
5
1375
by: Nathan Pinno | last post by:
Hi all, What's wrong with the following code? It says there is name error, that random is not defined. How do I fix it? # Plays the guessing game higher or lower. # Originally written by Josh Cogliati, improved first by Quique, then by Nathan Pinno. print "Higher or Lower" print
6
4383
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
42
3495
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage: ---------------------------------------------------- TypeError: addFile() takes exactly 1 argument (2 given) ----------------------------------------------------
4
1609
by: QQ | last post by:
Hi Here is part of my code typedef struct{ int len; char code; }Code; typedef struct{ .... Code *a;
2
1202
by: SteveAtMTV | last post by:
I am trying to create an array of references to arrays. When I run the code below, it shows the correct data being pushed onto the array, but when I print it out at the end, every value is "3". Any ideas? Thanks, Steve
1
1380
by: teh_sAbEr | last post by:
Ok, so this isn't necessarily a programming issue, but anyways. I've managed to write that random wallpaper changer i've been wanting to make, but i've run into a little problem. According to the MS Knowledge Base, SystemParametersInfo() can't take a .jpg file as an argument when changing the wallpaper (it doesn't work, i've tried it), only .bmps so i'm stuck converting one of my many wallpapers from .jpg to .bmp, passing that to...
16
4542
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the screen, when I open a file, the entire contents of the file is in fact being shown...so why can't I print it later? All of this code I am getting from a book (Chris Sells) and the net. The solution is to be found in the fact that stringbuilder is...
0
9964
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,...
1
11296
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,...
0
10659
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9858
agi2029
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...
1
8218
isladogs
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...
0
7389
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();...
0
6080
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...
1
4908
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
2
4450
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.