Thread: work with files in С99

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    1

    work with files in С99

    Each line of text file contains the name of a file found in the current
    directory. Copy the file, removing from it the names of non-existing files, and for
    each existing file, write down its size in bytes.

    My code
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdbool.h>
    #include <io.h>
    
    int main (int argc, char * argv[])
    {
        FILE  *myFile, *newFile, *tmpFile;
        char *mas;
        char nameFile[100];
    char i;
    	int sizeFile;
        if (argc != 2)
            {
                printf ("Some arguments are skipped\n");
                exit (1);
            }
    if ((myFile = fopen (argv[1], "r+")) == NULL)
            {
                printf ("Can't open %s\n", argv[1]);
                exit (1);
            }
    newFile = fopen("new.txt", "r+");
    //fscanf (myFile, "%s", nameFile);
    
    mas = fgets(nameFile,100,myFile);   
    
    if (!mas)
    		printf("\n End file or error \n");
    	else 
    	    {
    	    tmpFile = fopen("\"" nameFile "\"","rb");
    		printf("%s", nameFile);
    		fseek(tmpFile,0,SEEK_END);
    		sizeFile = ftell(tmpFile);
    		fseek(tmpFile,0,SEEK_SET);
                fprintf(newFile, "File name %s File name %d", nameFile, sizeFile);   
    	    }
     
    
    return 0;
    
    
    }

    help please !

    test.txt :

    test.c
    test.h
    Last edited by Salem; 05-05-2010 at 02:53 PM. Reason: Adde [code][/code] tags - learn to use them yourself

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with loading files into rich text box
    By blueparukia in forum C# Programming
    Replies: 3
    Last Post: 10-19-2007, 12:59 AM
  2. How do you work with resource files???
    By Finchie_88 in forum Windows Programming
    Replies: 4
    Last Post: 10-23-2004, 02:39 PM
  3. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. displaying text files, wierd thing :(
    By Gades in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 05:18 PM