help with program

This is a discussion on help with program within the C Programming forums, part of the General Programming Boards category; I'm working on a program thats supposed to read a line in, then pass it to a function which prints ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    help with program

    I'm working on a program thats supposed to read a line in, then pass it to a function which prints the line one word per line, like this,
    >>>> ENTER A LINE:
    this is a test
    <<<< RESULT (4 words):
    this
    is
    a
    test

    the code below is just the snippet from the function. My problem is it gives me warnings saying, "[Warning] passing arg 1 of `getc' from incompatible pointer type" and "[Warning] passing arg 2 of `putc' from incompatible pointer type". I'm not real sure what I'm doing wrong, any help would be appericated

    Code:
    #define MAXLEN 128
    
    int mystrtokens(char line[], char *words)
    {
        /* Variables */    
        char read[128];    
        char ch;
        char *word[MAXLEN]; 
        int count;
        int i = 0;
        do
        {        	
            do
            {
                ch = getc(*word);
                if(isspace(ch) != 0)
                {
                    *word = line;
                }
                else (putc('\0', line));      	  
        	    ++i;
            }while (*word != ' ' && *word != '\0');
                	    
        	++count;
        }while(line != EOF);
        
        return *word, count;
    }
    sorry I added the variables now
    Last edited by Brimak86; 11-13-2007 at 01:09 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    Well without seeing how you declared word or line (I'm guessing char or char*), it's hard to say.
    But getc and putc read and write a FILE* variable.

    > putc('\0', line)
    Perhaps \n would be better?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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