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 1949 horace1 1,510
Recognized Expert Top Contributor
the maximum path length should be defined by PATH_MAX in limits.h, see
http://www.opengroup.org/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...
|
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()...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |