Hi! This is my first post on the web ever!
To make it short, I made a routine to change certain bytes in a file in binary mode. It all worked perfectly, until I decided to use a long name directory and it crashes. I made certain check points to find out exactly where it crashes and why. Here is my subroutine code: -
void binary_edit (char *cur_dir) {
-
FILE *fp,*fp2;
-
char filename[100],filename2[100];
-
int temp,cur_bit=0;
-
sprintf(filename ,"%s\\file1.bin",cur_dir);
-
sprintf(filename2,"%s\\file2.bin",cur_dir);
-
fp=fopen(filename,"rb");
-
fp2=fopen(filename2,"wb");
-
-
temp=(int)fgetc(fp); //doesn't get here if filename=>41
-
while (!feof(fp)) {
-
switch (cur_bit) {
-
case 50:fputc(0,fp2);break;
-
case 51:fputc(1,fp2);break;
-
case 52:fputc(2,fp2);break;
-
case 53:fputc(3,fp2);break;
-
case 54:fputc(4,fp2);break;
-
case 55:fputc(5,fp2);break;
-
default:fputc(temp,fp2);
-
}
-
temp=(int)fgetc(fp);
-
}
-
-
//doesn't get here if filename2=>39
-
fclose(fp);
-
fclose(fp2);
-
unlink(filename);
-
SleepEx(1000,false);
-
rename(filename2,filename);
-
}
-
Thanking you in advance
Mario
1 1965 horace1 1,510
Recognized Expert Top Contributor
the maximum path length should be defined by PATH_MAX in limits.h, see
http://www.opengroup.o rg/onlinepubs/009695399/functions/fopen.html
try the following program -
/* display maximum path and file name length */
-
-
#include <stdio.h>
-
#include <limits.h>
-
-
int main()
-
{
-
printf(" maximum path length %d ", PATH_MAX);
-
printf(" maximum name length %d ", NAME_MAX);
-
getchar();getchar();getchar();getchar();
-
}
-
-
some compilers don't define NAME_MAX and some define neither of them
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Anthony Lansbergen |
last post by:
Hi,
My (pre)compiler(s) (borland C++ builder 5 and g++) both seems to have a
problem with the new include format.
In stead of #include <iostream.h> I want to say #include <iostream>.
This works fine for short filenames (<8 chars), but it doesn't work for long
filenames.
|
by: William L. Bahn |
last post by:
I'm sure this has been asked before, and I have looked in the FAQ, but I'm
looking for an explanation for the following:
The functions pairs:
gets()/fgets()
puts()/fputs()
printf()/fprintf()
scanf()/fscanf()
|
by: Kobu |
last post by:
Do the "larger" input functions like scanf, gets, fgets use fgetc to
take input or an operating system call function like read() (I know it
could be any "way", but I'm trying to find out how it's best to "think
of it")?
I've seen some explain it as if they call fgetc internally, then I've
seen some people explain it as if they call some lower level OS system
call like read(). I've even seen some older posts talk about a input
functions...
|
by: Pieter |
last post by:
I want to be able to split regular MAX_PATH length filenames and 32K UNICODE
filenames using the \\?\ naming convention.
Are there any equivalents to _tsplitpath() for long names, or am I left to
writing my own split code?
Thanks
Pieter
|
by: cinsky |
last post by:
Hi,
While reading ISO C Standard, I found follow text in 7.19.8.1:
size_t fread(void *restrict ptr, size_t SIZE, ...)
... For each object, SIZE calls are made to the fgetc function
and the results stored, in the order read, in an array of
unsigned char exactly overlaying the object.
| |
by: chongming |
last post by:
Hi, i want to display all the filenames on browser. However i found that if there are many filenames in that folder, result will be it will display a long list of filenames on that browser.
My question is how do i iterate the file names with 5 filenames on each page?
I have manage to retrieve and display the filenames with the codes below. Can anyone help me or give advice on how to do the iteration?
The codes are below and able to...
|
by: primeSo |
last post by:
// FIRST
int main(void){
int c, i = 0;
char cArray;
while( (c = getchar()) != '\n' && c != EOF){
cArray = c;
i ++;
}
|
by: Praesidium |
last post by:
I'm having a bit of a problem running a C program I'm working on (compiled in cygwin). There's a way to go, as I'm intent on making sure each bit works before moving on to the next. As it appears now:
# include <stdio.h>
# include <string.h>
int main(void)
{
printf("Fine at line 6");
FILE *source;
char string1;
|
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= |
last post by:
Hi,
I work in a company where we tend to use very deep folder structures and
long descriptive file names due to the nature of the analysis that we make.
I've made a program that recursively descends into these folders to do some
search stuff. However, I receive an exception trown from a FileInfo object
when I'm deep down the mine shaft saying that "the specified path/file is too
long and must not exceed 248/260 respectively in...
|
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: 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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |