Thread: Binary Input File to Array

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >The red line should return a NULL if the condition failed
    Right, so Matsp's point was, where does it return to, and when do you actually call Print()?

  2. #17
    Registered User
    Join Date
    Apr 2008
    Posts
    14

    Unhappy

    well since its a pointer array the values are passed by address but the return should just go back to main() so it can call the PRINT Function and display all the content thier would someone please give me an idea

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by siLent0 View Post
    well since its a pointer array the values are passed by address but the return should just go back to main() so it can call the PRINT Function and display all the content thier would someone please give me an idea
    Look at main:
    Code:
    int main()
    {
         fopen_s(&fp,"FILE.DAT","rb")
        getWord(fp);
    }
    Where, pray tell, do you see "print" anywhere?

  4. #19
    Registered User
    Join Date
    Apr 2008
    Posts
    14
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    
    void getWords(char * wbuf);
    void output();
    FILE *fp;
    
    int main (void)
    
    {
         
    	fopen_s(&fp,"file.dat", "rb");
    	
        getWord(fp);
    	output();
    	
    	
    
    }
    
           // Begining of Get Word Function
    // This Function Reads The input of a Text File
    void getWords(char* wbuf) {
    
          int c, i = 0;
    
     
    
          while ((c = fgetc(fp)) != EOF)
    
                if (isalpha(c) || ispunct(c))
    			{
                      wbuf[i++] = c;
    			     
    			}
                else {
    
                      wbuf[i] = '\0';
    
                      return;
    
                }
    
          wbuf[i] = '\0';
    
    }
    void output(char wbuf[])
    { 
      
      
    }

  5. #20
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >    getWord(fp);
    fp is of type FILE *. You should be passing a char array of some sort:
    Code:
        char word[100];
    .
    .
        getWord(word);
    Code:
    >	output();
    The same is true for output(). You should pass the word returned from getWord():
    Code:
    	output(word);
    By the way your compiler should warn you about some of these errors. If it's not, you may need to change the compiler's warning level.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. how do you input data from a file into an array?
    By jorgejags in forum C Programming
    Replies: 5
    Last Post: 11-03-2008, 02:48 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. Deletion of input in Binary File
    By supz in forum C++ Programming
    Replies: 1
    Last Post: 04-14-2003, 04:48 AM