Thread: cannot read long file name

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Unhappy cannot read long file name

    Anyone can help ??

    My program cannot read the long file name under NT.

    e.g. if the file name is "input.txt" , it can work.
    However, if the file name is "input20020331.txt" , it cannot.

    Anything wrong ????

    Below is my prog.

    -------------------------------------------------------------------------------
    /*
    program to split file content into two files
    */

    #include <stdio.h>
    #include <string.h>

    #define INFILE_WIDTH 3000
    #define MAX_LINE 60000

    void main(int argc, char *argv[])
    {
    FILE *in_file;
    FILE *out_file1;
    FILE *out_file2;
    char linebuf[INFILE_WIDTH + 1];
    char outfilename1[40];
    char outfilename2[40];
    char extension[20];
    char prefix[40];
    char suffix[40];
    int ext_pos = 0 ;
    int i, filename_len;

    char infilename[40];
    float cut_line = MAX_LINE;


    int j=0;
    float line_count = 0;

    float out_count1 =0;
    float out_count2 =0;

    strcpy(infilename,argv[1]);

    if (argc >= 2 ) {
    // This line is not work ..........!!!!!!!!!!!!!
    if ((in_file = fopen(argv[1],"r")) == NULL)
    {
    printf("Cannot open file %s\n", argv[1]);
    exit(8);
    }

    filename_len = strlen((char *)argv[1]);
    prefix[0]='\0';
    suffix[0]='\0';
    for (i=0; i < filename_len; i ++)
    {
    if((ext_pos == 0) && (argv[1][i]=='.'))
    ext_pos = i;

    if(ext_pos > 0)
    {
    suffix[j++]=argv[1][i];
    suffix[j]='\0';
    }
    else
    {
    prefix[i]=argv[1][i];
    prefix[i+1]='\0';
    }
    }


    sprintf((char *)outfilename1,"%s1%s", prefix, suffix);
    sprintf((char *)outfilename2,"%s2%s", prefix, suffix);

    if ((out_file1 = fopen(outfilename1,"w+"))== NULL)
    {
    printf("Error create file %s\n", outfilename1);
    exit(8);
    }
    if ((out_file2 = fopen(outfilename2,"w+"))== NULL)
    {
    printf("Error create file %s\n", outfilename2);
    exit(8);
    }



    if (argc > 2)
    cut_line = atof(argv[2]);


    while (fgets(linebuf, INFILE_WIDTH, in_file) != NULL)
    {
    line_count +=1;
    if (line_count <= cut_line)
    {
    fputs((char *)linebuf, out_file1);
    out_count1 +=1;
    }
    else
    {
    fputs((char *)linebuf, out_file2);
    out_count2 +=1;
    }

    linebuf[0]='\0';
    }

    fclose(in_file);
    fclose(out_file1);
    fclose(out_file2);

    printf("\nSource :%s (%.0f lines)",argv[1],line_count);
    printf("\nOutput :%s (%.0f lines)",outfilename1,out_count1);
    printf("\n :%s (%.0f lines)",outfilename2,out_count2);

    }
    else
    {
    printf("\n\n");
    printf("\n----------------------------------------------------------------");
    printf("\nDesc : This program is used to split file content into two files on PC");
    printf("\n\nSPLIT.EXE [filename] [line_no]");
    printf("\n\n filename - source file name");
    printf("\n\n line_no - optional");
    printf("\n - max. no of lines in the first output file");
    printf("\n - default 60000");

    }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Does EVERYONE who comes to these boards use void main? It seems like only the regulars know better. I mean geez, are programming teachers THAT [expletive deleted] stupid? Not that the students seem to be any brighter, but still!

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Smile using win32 complier


  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    12
    Originally posted by Prelude
    I mean geez, are programming teachers THAT [expletive deleted] stupid?
    yes, yes they are. at least mine are. i was first taught to void main, then later expected not to, but not taught what else to do, so i still use it.

  5. #5
    Unregistered
    Guest

    Talking

    If you use a DOS compiler you will have to provide and use filenames of the conventional DOS style i.e.,8+.+3 type.
    I hope you understand.
    Deepak
    [email protected]

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If you use a DOS compiler you will have to provide and use filenames of the conventional DOS style i.e.,8+.+3 type.
    I hope you understand.

    ..unless you code your own file functions that read LFN. It is possible in DOS.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM