Like Tree4Likes
  • 4 Post By Salem

Strtok - Expected expression and too few arguments?

This is a discussion on Strtok - Expected expression and too few arguments? within the C Programming forums, part of the General Programming Boards category; I've been tasked to do a program that separates and changes words from a string of words separated by " ...

  1. #1
    Registered User TheWhiffet's Avatar
    Join Date
    Apr 2011
    Location
    Hell.
    Posts
    14

    Strtok - Expected expression and too few arguments?

    I've been tasked to do a program that separates and changes words from a string of words separated by " "(spaces) but I can't seem to make strtok work. I get errors saying: "Expected expression before 'char' and Too few arguments" Can you please help me identify the problem and how I could fix it?

    PS: I do know that the gets(); function is dangerous but my teacher specifically instructed us to use it. I can't use anything else for input.

    Main
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "header.h"
    
    main()
    {
    	char str[350];
    	char token[350];
    	gets(str);
    	inputProcess(char *str,char *token);
    }
    header.h
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    char inputProcess(char*input, char*tok){
    	
    	tok = strtok(input," ");
    	while(tok!= NULL)
    	{
    		printf("%s",tok);
    		tok=strtok(NULL," ");
    	}
    }
    Help would be very much appreciated.
    Last edited by TheWhiffet; 07-26-2011 at 07:00 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    inputProcess(char *str,char *token);
    You got the function calls correct in your inputProcess function -- you should get them right here too.

    (And no putting code in a header!)

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,292
    For starters:

    Code:
    main()
    {
    	char str[350];
    	char token[350];
    	gets(str);
    	inputProcess(char *str,char *token);
    }
    You only need to reference the variables here, you do not need to re-declare them. "str" and "token" would be the correct arguments to pass to this function.

    Also, your "inputProcess()" function is expecting to return a value of type "char."

    And your "main()" should be like this:

    Code:
    int main(void)
    {
        // code
    
        return 0;
    }

  4. #4
    Registered User TheWhiffet's Avatar
    Join Date
    Apr 2011
    Location
    Hell.
    Posts
    14
    Thank you guys for the input! I got it to work now!

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by TheWhiffet View Post
    Thank you guys for the input! I got it to work now!
    Good... now move the function into your main file and stop putting live code in headers (.h) files... It may have worked this time but it's going to cause you many many headaches down the road.

    Also, if your instructor is specifically telling you to use gets()... it may be prudent to question his programming skills and teaching ability. Your career may one day hinge on his mistakes!

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Please send your "teacher" to this forum for some "re-education" lessons.

    Or find another teacher, because the one you have is broken.
    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. Expected primary expression
    By MarlonDean in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2008, 03:43 PM
  2. expected primary expression
    By lilhawk2892 in forum C++ Programming
    Replies: 10
    Last Post: 11-22-2007, 06:50 PM
  3. Expected primary expression?
    By Beowolf in forum C++ Programming
    Replies: 17
    Last Post: 11-11-2007, 08:57 PM
  4. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM
  5. expected constant expression
    By Brian in forum C Programming
    Replies: 4
    Last Post: 12-03-2003, 02:30 PM

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