Hello everybody,
I am getting a "segmentati on fault" error when i compile the following
piece of code. The program runs fine till it encounters the line of
code saying" FILE_lic=fopen. ........". And after that, it terminates
saying segmentation fault. I had included the appropriate header files
also! I couldn't makeout where the problem exists in the program. Can
anyone solve this mistery!
void LICENSEinfo::fi nd()
{
char check[10],vendor[20],date[12];
char uw1[20],uw2[20],mystring[200];
int lic_num;
char filestring[20];
struct dirent *dp, *subdp;
DIR *dir, *subdir;
FILE *FILE_list;
FILE *FILE_lic;
FILE_list = fopen("/tmp/list","w");
// Make "/parent" as the present working directory
chdir ("/parent");
dir=opendir("." );
while ((dp=readdir(di r))!=NULL)
{
if(!strcmp(dp->d_name,".")||! strcmp(dp->d_name,"..") )
continue;
subdir=opendir( dp->d_name);
while ((subdp=readdir (subdir))!=NULL )
{
if(!strcmp(subd p->d_name,".")||! strcmp(subdp->d_name,"..") )
continue;
if(strstr(subdp->d_name,"_lic") !=0)
{
// read the entire file
strcpy(filestri ng,subdp->d_name);
FILE_lic = fopen(filestrin g,"r");
// problem: FILE_lic is reset to 0x0 here.
while (feof(FILE_lic) ==0)
{
fgets(mystring, 200,FILE_lic);
if((strstr(myst ring,"INCREMENT "))||(strstr(my string,"FEATURE ")))
{
sscanf(mystring ,"%s%s%s%s%s%d" ,check,uw1,vend or,uw2,date,&li c_num);
fprintf (FILE_list,"%s \t %s \t %d \n",vendor,date ,lic_num);
}
}
}
}
}
}
Thanks in advance 2 5451
Hi,
"Abhijit" <ab*********@ya hoo.com> wrote in message
news:45******** *************** **@posting.goog le.com... Hello everybody,
I am getting a "segmentati on fault" error when i compile the following piece of code. The program runs fine till it encounters the line of code saying" FILE_lic=fopen. ........". And after that, it terminates saying segmentation fault. I had included the appropriate header files also! I couldn't makeout where the problem exists in the program. Can anyone solve this mistery!
void LICENSEinfo::fi nd() { char check[10],vendor[20],date[12]; char uw1[20],uw2[20],mystring[200]; int lic_num; char filestring[20];
struct dirent *dp, *subdp; DIR *dir, *subdir;
FILE *FILE_list; FILE *FILE_lic;
FILE_list = fopen("/tmp/list","w");
// Make "/parent" as the present working directory chdir ("/parent");
dir=opendir("." ); while ((dp=readdir(di r))!=NULL) { if(!strcmp(dp->d_name,".")||! strcmp(dp->d_name,"..") ) continue;
subdir=opendir( dp->d_name); while ((subdp=readdir (subdir))!=NULL ) { if(!strcmp(subd p->d_name,".")||! strcmp(subdp->d_name,"..") ) continue;
if(strstr(subdp->d_name,"_lic") !=0) {
// read the entire file strcpy(filestri ng,subdp->d_name); FILE_lic = fopen(filestrin g,"r");
In the current directory there isn't a file with the contents of
subdp->d_name. Hence fopen can't find the file and returns 0.
You should first change with chdir to the child directory you are reading
from. Though you opened the subdir for reading with readdir, your working
directory is still set to the parent of the subdir.
Regards, Ron AF Greve.
// problem: FILE_lic is reset to 0x0 here. while (feof(FILE_lic) ==0) { fgets(mystring, 200,FILE_lic); if((strstr(myst ring,"INCREMENT "))||(strstr(my string,"FEATURE "))) { sscanf(mystring ,"%s%s%s%s%s%d" ,check,uw1,vend or,uw2,date,&li c_num); fprintf (FILE_list,"%s \t %s \t %d \n",vendor,date ,lic_num); } }
}
} }
}
Thanks in advance
Abhijit wrote: Hello everybody,
I am getting a "segmentati on fault" error when i compile the following piece of code. The program runs fine till it encounters the line of code saying" FILE_lic=fopen. ........". And after that, it terminates saying segmentation fault. I had included the appropriate header files also! I couldn't makeout where the problem exists in the program. Can anyone solve this mistery!
FILE_lic = fopen(filestrin g,"r"); // problem: FILE_lic is reset to 0x0 here.
Do you understand what it means when the return value from fopen() is
0? If not, why not? What book are you using?
Do you understand that FILE_lic is a pointer? Do you understand what
happens if you attempt to use a null pointer? If not, why not?
Brian Rodenborn This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hans-Joachim Widmaier |
last post by:
Hi all.
Handling files is an extremely frequent task in programming, so most
programming languages have an abstraction of the basic files offered by
the underlying operating system. This is indeed also true for our language
of choice, Python. Its file type allows some extraordinary convenient
access like:
for line in open("blah"):
handle_line(line)
|
by: moonriver |
last post by:
I write a program accessing files in network drive o:. It is doable as a standalone application. However, if it is running under windows service, the following exception will appear:
13/07/2004 10:24:48 AM run() error: System.IO.IOException: The specified network password is not correct.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare...
|
by: Lee Swanson |
last post by:
Hi,
I have a fairly large visual studio.net solution made up of about 8
projects. I needed to update a usercontrol in one of these projects, but
when I tried to open it I got the error 'The process cannot access the file
because it is being used by another process.". This error also stopped me
from compiling.
I tried everything to open this file. Restarting the server, recreating my
solution, copying the files, renaming them and then...
|
by: Mark |
last post by:
Hello,
I have researched and tried every thing I have found on the web, in groups
and MS KB articles. Here is what I have.
I have a Windows 2000 Domain Controller all service packs and every thing
else from windows update.
..NET 1.0 and 1.1 installed on the server. Actually .NET was installed
before the server was made a DC.
|
by: JimmyKoolPantz |
last post by:
IDE: Visual Studio 2005
Language: VB.NET
Fox Pro Driver Version: 9.0.0.3504
Problem: I currently have a problem altering a DBF file. I do not get
any syntax errors when running the program. However, after I alter the
table and open microsoft excel to look at any changes; I get the
following error: "This file is not in a recognizable format" If I do
open the file in excel it looks like its not formatted.
| |
by: hidara |
last post by:
I have an excel file that I need to check if its in use by another before i open it.
I have found various forms of the follwing code but each one give me the same errors at the following 2 lines when I compile it using vb.net 2005 express
(1)
Open strFileSpec For Input Lock Read As intFn
'error = open not declared, missing comma etc.
(2)
Close(intFn)
'error = to...
|
by: ArmageddonAsh |
last post by:
I'm trying to make an application that will allow the user to enter data into a flexgrid (that's done) and then save the data from that flexgrid into a CSV file but even though the file is made none of the data from the flexgrid goes into the CSV file and so I have a couple of questions.
1, How do I make the application load the data from a specific CSV file?
2, How do I make it so that the user is able to add information to the data and...
|
by: tshad |
last post by:
I am trying to get access to a file that may still being written because the
file is so large (7-10MB).
I get an error:
The process cannot access the file 'c:\TestDocs\XMLFiles\492172.XML' because
it is being used by another process
|
by: Don |
last post by:
I wrote an app that alerts a user who attempts to open a file that the
file is currently in use. It works fine except when the file is
opened by Notepad. If a text file is opened, most computers are
configured to use Notepad to open the file by default and if they are
configured to use Notepad by default I want it to remain that way
rather than retrieve the text into my app or force the user to use
another app to read the file. I'm...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script.
What You Need
Any recent...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
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
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |