fd copy

This is a discussion on fd copy within the C Programming forums, part of the General Programming Boards category; This is the program which creates the image of FDD. I want to change the program which copies the specified ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    11

    Unhappy fd copy

    This is the program which creates the image of FDD.
    I want to change the program which copies the specified file.
    And lose the start function after pushing key.
    Where should I modify?
    (ex;
    a:\>dir
    A.txt
    B.txt
    program.exe
    a:\>program.exe A.txt(enter) <- Copy start
    end
    )
    I am sorry to be an elementary question.
    mary

    -----
    int main(int argc, char *argv[])
    {
    int i, j, error;
    int drive;
    FILE *fp;
    char *cptr, a, b;

    if (argc < 3)
    {
    printf("\n\ndskcpy [drive:] [filename] or dskcpy [filename] [drive:]\n");
    return(1);
    }

    cptr = argv[1];
    i = strlen(cptr) - 1;
    a = cptr[i];

    cptr = argv[2];
    j = strlen(cptr) - 1;
    b = cptr[j];

    if (a == ':' && b == ':')
    {
    printf("\ninvalid arguments\n");
    return(1);
    }

    if (a == ':')
    {
    direction = DISKETTE_TO_FILE;
    filename = argv[2];
    drive = toupper(*argv[1]) - 'A';

    }
    else if (b == ':')
    {
    direction = FILE_TO_DISKETTE;
    filename = argv[1];
    drive = toupper(*argv[2]) - 'A';
    }
    else
    {
    printf("\ninvalid arguments\n");
    return(1);
    }

    if (drive < 0 || drive > 1)
    {
    printf("\n\nInvalid drive letter\n");
    return(1);
    }

    if (direction == FILE_TO_DISKETTE)
    fp = fopen(filename, "rb");
    else
    fp = fopen(filename, "wb");

    if (!fp)
    {
    printf("\nCan't open disk file!\n");
    return(1);
    }

    if (direction == FILE_TO_DISKETTE)
    error = write_disk(drive, fp);
    else
    error = read_disk(drive, fp);

    printf("\nSuccess.\n");

    return(error);
    }

    int read_disk(int drive, FILE *fp)
    {
    int i, error, size;
    int track, cyl, sec, head;

    error = FALSE;
    printf("\nInsert source diskette and press <ENTER>... "); <-delete.
    i = getch();
    printf("\n");
    if (i == ENTER)
    {
    i = get_drive_parameter(drive, fp);
    if (i)
    return(1);

    size = max_sec * BYTES_PER_SECTOR;

    for (track=0; track<=max_cyl; track++)
    {
    error = read_track(drive, track, max_sec, 0);
    if (error)
    {
    printf("\nError reading track %d\n", track);
    break;
    }
    fwrite(buffer, 1, size, fp);
    if (max_head)
    {
    error = read_track(drive, track, max_sec, 1);
    if (error)
    {
    printf("\nError reading track %d\n", track);
    break;
    }
    fwrite(buffer, 1, size, fp);
    }
    }
    fflush(fp);
    }
    fclose(fp);
    recal(drive);
    return(error);
    }

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    28
    How about posting your #include files and I'll see if I can get it to work.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    11
    Thank you for a reply!
    mary

    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <ctype.h>
    #include <dos.h>
    #include <bios.h>
    #include <string.h>
    #include <io.h>

    #ifndef FALSE
    #define FALSE 0
    #endif
    #ifndef TRUE
    #define TRUE 1
    #endif

    #define byte unsigned char
    #define word unsigned int
    #define ulong unsigned long

    #define ENTER 0x0d
    #define SECTORS_PER_TRACK 18
    #define BYTES_PER_SECTOR 512
    #define TRACK_SIZE (SECTORS_PER_TRACK * BYTES_PER_SECTOR)

    #define RST_CMD 0
    #define RD_CMD 2
    #define WR_CMD 3
    #define PARM_CMD 8

    #define RETRY_COUNT 3

    #define DISKETTE_TO_FILE 0
    #define FILE_TO_DISKETTE 1

    int read_disk(int drive, FILE *fp);
    int write_disk(int drive, FILE *fp);
    int recal(int drive);
    int read_track(int drive, int track, int len, int head);
    int write_track(int drive, int track, int len, int head);
    int get_drive_parameter(int drive, FILE *fp);
    int key_check(void);

    int max_cyl,max_sec,max_head;
    char *filename;
    byte direction;
    byte buffer[TRACK_SIZE];

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    This is the program which creates the image of FDD.
    I want to change the program which copies the specified file.
    And lose the start function after pushing key.
    Where should I modify?
    Can you rephrase your question please, I'm not sure I understand what you want.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    11
    Thank you for reply!

    This program creates the image of FDD.
    So change the program which copies the specified file in FDD .

    -----------
    ex DOS command.
    A:>dir
    A:>A.txt
    B.txt
    C.txt
    C:test>program.exe a:\A.txt(enter)
    C:test>dir
    C:test>program.exe
    A.txt <- copy was made.
    -----------
    Please modify it as mentioned above.
    The display of "press <ENTER>..." is not needed.

    I am sorry to be poor at the explanation.
    mary

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    So, do you just want to remove the section of code that asks the user to "Insert source diskette and press <ENTER>" ?

    If so, a simple fix would be to do the following:

    - Replace these lines of code:
    >printf("\nInsert source diskette and press <ENTER>... ");
    >i = getch();
    >printf("\n");

    with this one
    >i = ENTER;

    So it now looks like:
    Code:
    int read_disk(int drive, FILE *fp)
    {
        int i, error, size;
        int track, cyl, sec, head;
    
        error = FALSE;
        i = ENTER;
        if (i == ENTER)
        {
            i = get_drive_parameter(drive, fp);
    .....
    .....
    Alternatively (and preferably), you could remove the if statement that checks the value of i against ENTER as this is no longer required.

    If this hasn't helped.... ask again.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > I am sorry to be poor at the explanation.
    I haven't seen Engrish in awhile.

    Please speak your intentions so we may be of assistance to yourself.
    The world is waiting. I must leave you now.

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    11
    I am studying a C program and English...

    >So, do you just want to remove the section of code that asks the user to "Insert source diskette and press <ENTER>" ?

    I want to lose action of "press <ENTER>".
    Copy is started immediately when the file in FDD is specified.

    I modifyed the 80 to 82th line as follows.
    -----------
    int read_disk(int drive, FILE *fp)
    {
    int i, error, size;
    int track, cyl, sec, head;

    error = FALSE;
    i = ENTER;
    if (i == ENTER)
    {
    i = get_drive_parameter(drive, fp);
    ------------

    And execution.
    -----------
    C:>program.exe a:\A.txt(enter)
    Insert source diskette and press <ENTER>... <- copy of a file does not start.
    -----------
    Where is wrong?
    Is it short of my modification??

    mary

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >I want to lose action of "press <ENTER>".
    >Copy is started immediately when the file in FDD is specified.
    >I modifyed the 80 to 82th line as follows.
    >And execution.
    -----------
    C:>program.exe a:\A.txt(enter)
    Insert source diskette and press <ENTER>... <- copy of a file does not start.
    -----------

    Are you sure you recompile worked OK? If you have removed that text from your program, how can it still be outputing it?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    11
    This program creates the image of FDD and lose action of "press <ENTER>".
    But my demand is the program which specifies and copies a file.
    I want to specify not the whole of FDD but a file.

    mary

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    But my demand is the program which specifies and copies a file.
    I want to specify not the whole of FDD but a file.
    OK, I'm not sure if this will help you or not.... I have written this copy program for you to have a look at.

    It allows you to run it in any of the following ways:
    >mycopy a:\myfile.txt
    - This will copy to the current working directory, with filename of myfile.txt
    >mycopy a:\myfile.txt mynewfile.txt
    - This will copy to the current working directory, with filename of mynewfile.txt
    >mycopy a:\myfile.txt c:\mydir\mynewfile.txt
    - This will copy to the directory c:\mydir, with filename of mynewfile.txt

    It assumes you are using DOS style filenames (ie backslashes).

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAXL_NAME 128
    
    char *MakeFileName(char *, char *);
    
    int main(int argc, char *argv[])
    {
    	FILE *ifp, *ofp;
    	char fromfile[MAXL_NAME], tofile[MAXL_NAME];
    	int c;
    	
    	switch (argc)
    	{
    		case 2:
    			strncpy(fromfile, argv[1], sizeof (fromfile));
    			if (MakeFileName(fromfile, tofile) == NULL)
    			{
    				printf ("Cannot set second filename\n");
    				return (EXIT_FAILURE);
    			}
    				
    			break;
    		case 3:
    			strncpy(fromfile, argv[1], sizeof (fromfile));
    			strncpy(tofile, argv[2], sizeof (tofile));
    			break;
    		default:
    			printf ("No filename specified\n"); 
    			return (EXIT_FAILURE);
    			break;
    	}
    	
    	fromfile[MAXL_NAME-1] = '\0';
    	tofile[MAXL_NAME-1] = '\0';
    	
    	if ((ifp = fopen(fromfile, "rb")) == NULL)
    	{
    		perror (fromfile);
    		return (EXIT_FAILURE);
    	}
    	
    	if ((ofp = fopen(tofile, "wb")) == NULL)
    	{
    		perror (tofile);
    		return (EXIT_FAILURE);
    	}
    
    	printf ("Copy from %s to %s\n", fromfile, tofile);
    		
    	while ((c = fgetc(ifp)) != EOF && fputc(c, ofp) != EOF);
    	
    	if (ferror(ifp))
    		perror(fromfile);
    	if (ferror(ofp))
    		perror(tofile);
    	
    	printf ("Complete\n");
    	
    	fclose (ifp);
    	fclose (ofp);
    	return EXIT_SUCCESS;
    }
    
    char *MakeFileName(char *in, char *out)
    {
    	/*
    	 * This function takes a fully qualified filename (in) and 
    	 * copies only the non-qualified name to out.
    	 * Allow for two types of filename:
    	 *   c:\mydir\myfile.txt
    	 *   c:myfile.txt
    	 * In either case the out variable will contain myfile.txt
    	 * On success a pointer to out is return,
    	 * on failure NULL is returned.
    	 */
    	 
    	char *p;
    	
    	if (in == NULL || out == NULL)
    		return (NULL);
    	
    	if ((p = strrchr(in, '\\\')) == NULL)
    		if ((p = strrchr(in, ':')) == NULL)
    			return (NULL);
    
    	/* Ensure that the slash or colon wasn't the 
    	 * last character in the string
    	 */
    	if (++p)
    		strcpy (out, p);
    	else return (NULL);
    	
    	return (out);
    }
    If this isn't what you want, can you rephrase your question please.

    Have fun
    Last edited by Hammer; 07-25-2002 at 04:27 AM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #12
    Registered User
    Join Date
    Jun 2002
    Posts
    11

    Smile

    This is a program as my demand!!!!
    My problem was solved.
    Thank you for a good program!!!


    mary

  13. #13
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by mary
    This is a program as my demand!!!!
    My problem was solved.
    Thank you for a good program!!!
    Your welcome.....

    A quick English lesson for you.. the word "demand" means you want it NOW, and is not very friendly. Words to use instead would be
    - But my request is a program which specifies and copies...
    - I am asking for...
    - I would like to know...
    I understand your use of the word demand, but others may not.

    Have fun, and come back again when you have more problems.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calling copy constructor from template
    By Ancient Dragon in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2005, 01:54 PM
  2. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  3. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  4. Copy Constructor crashing program
    By bob2509 in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2002, 03:21 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 10:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21