Thread: help with program

  1. #1
    Registered User
    Join Date
    Apr 2007

    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):

    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

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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

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, 01: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, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM