473,670 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fgetc/fpostc crashes with long filenames

1 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. void binary_edit (char *cur_dir) {
  2.     FILE *fp,*fp2;
  3.     char filename[100],filename2[100];
  4.     int temp,cur_bit=0;
  5.     sprintf(filename ,"%s\\file1.bin",cur_dir);
  6.     sprintf(filename2,"%s\\file2.bin",cur_dir);
  7.     fp=fopen(filename,"rb");
  8.     fp2=fopen(filename2,"wb");
  9.  
  10.     temp=(int)fgetc(fp); //doesn't get here if filename=>41
  11.     while (!feof(fp)) {
  12.         switch (cur_bit) {
  13.             case 50:fputc(0,fp2);break;
  14.             case 51:fputc(1,fp2);break;
  15.             case 52:fputc(2,fp2);break;
  16.             case 53:fputc(3,fp2);break;
  17.             case 54:fputc(4,fp2);break;
  18.             case 55:fputc(5,fp2);break;
  19.             default:fputc(temp,fp2);
  20.         }
  21.         temp=(int)fgetc(fp);
  22.     }
  23.  
  24.      //doesn't get here if filename2=>39
  25.     fclose(fp);
  26.     fclose(fp2);
  27.     unlink(filename);
  28.     SleepEx(1000,false);
  29.     rename(filename2,filename);
  30. }
  31.  
Thanking you in advance

Mario
Nov 19 '06 #1
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
Expand|Select|Wrap|Line Numbers
  1. /* display maximum path and file name length */
  2.  
  3. #include <stdio.h>
  4. #include <limits.h>
  5.  
  6. int main()
  7. {
  8.        printf(" maximum path length %d ", PATH_MAX);
  9.        printf(" maximum name length %d ", NAME_MAX);
  10.        getchar();getchar();getchar();getchar();
  11.        }
  12.  
  13.  
some compilers don't define NAME_MAX and some define neither of them
Nov 19 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1737
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.
13
15116
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()
6
2282
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...
1
3924
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
3
3339
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.
0
2502
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...
9
5141
by: primeSo | last post by:
// FIRST int main(void){ int c, i = 0; char cArray; while( (c = getchar()) != '\n' && c != EOF){ cArray = c; i ++; }
2
4401
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;
2
1939
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...
0
8903
Oralloy
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...
0
8814
jinu1996
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...
1
8592
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
8661
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...
1
6213
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
5684
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
4211
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...
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
bsmnconsultancy
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...

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.