Thread: File questions

  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    File questions

    Can anyone give me some help as to why my code hangs.? assume that i've passed a proper argument.
    Code:
    /*gets all the digits in a text file and puts to stdout
    this seems to just hang. don't know why and i'm very annoyed.  */
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    int main(int argc, char *argv[]){
        int ch;
        FILE *file;
        
        if ( (file = fopen(argv[1], "r") ) == NULL)
        	puts("Unable to open file");
        	getchar();
        	return 1;
        	
       	while( ( ch = fgetc(file) ) != EOF){
       	    if (isdigit(ch))
       	       putchar(ch);
    	       
       	   }
           
        if ( fclose(file) !=0)
           puts("Unable to close file");
           
         getchar();
         return 0;
     }
    NEVER MIND!!!!
    Last edited by caroundw5h; 09-20-2004 at 04:54 PM. Reason: so embarrased!!! where is the delete button!!!
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Code:
        if ( (file = fopen(argv[1], "r") ) == NULL)
        	puts("Unable to open file");
        	getchar();
        	return 1;
    look at your getchar it isn't in the for loop
    [edit]I didn't see the nevermind[/edit]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM