Thread: i don't understand why this won't compile

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    19

    i don't understand why this won't compile

    Code:
    #include <stdio.h>
    #define MAX 100
    //void initialize(char string1storage[]);//initializes strings probably
    char *gets_s(char s[], int num);
    void getstring(char string1storage[]);
    void main(void)
    {//strings need2be initialized with anagram first?
    	
    	char string1storage[MAX];//stores first anagram string
    	//initialize(); //maybe call him after getstring?
    	getstring(string1storage[MAX - 1]);
    }
    //letterincrement[index] = f(that sees char type), for every reoccuring letter
    /*void initialize()
    {
    	char stringstorage[26];
    }*/
    
    void getstring(char string1storage[])
    {	
    	printf("Please enter a word or phrase");
    	gets_s(string1storage, MAX - 1);//MAX -1 because index starts@0
    }
    thanks


    anagrams.c(11): error C2664: 'getstring' : cannot convert parameter 1 from 'char' to 'char []'

  2. #2
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70
    As per "getstring" function definition, its taking array of characters in its argument. But while calling this function inside the main function, you are passing only one character i.e "string1storage[99]". That is the reason for the error.

    Is the above one is the complete code?
    Because i don't see the function definition for "gets_s" function.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    main returns int, not void

    > getstring(string1storage[MAX - 1]);
    To pass an array to a function, it is just the array name
    Like
    getstring(string1storage);
    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.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    19
    Quote Originally Posted by ArunS View Post
    As per "getstring" function definition, its taking array of characters in its argument. But while calling this function inside the main function, you are passing only one character i.e "string1storage[99]". That is the reason for the error.

    Is the above one is the complete code?
    Because i don't see the function definition for "gets_s" function.
    gets_s is in the standard c library

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    No it isn't.
    gets_s is microsoft's abomination at trying to write a "safe" version of gets()


    If you want it portable, use fgets()
    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.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by nospammax
    gets_s is in the standard c library
    It isn't. It is an extension to the standard library.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Apr 2011
    Posts
    19
    thanks everyone

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compile warning that i don't understand
    By fatsrir in forum C Programming
    Replies: 6
    Last Post: 07-08-2010, 04:26 PM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Replies: 3
    Last Post: 03-07-2003, 09:06 PM
  4. Can't compile, don't understand why
    By WebSnozz in forum C Programming
    Replies: 5
    Last Post: 10-22-2002, 05:07 AM